Use a proper parser for link detection
See original GitHub issueThere will always be issues with URL matching using regex as some cases simply can’t be caught with regex. An example where regex will fail is including brackets in URLs but only when the brackets are opened within the url:
- Include brackets:
http://<domain>.com/foo(bar)
- Don’t include wrapping brackets:
(http://<domain>.com/foobar)
- Include commas:
http://<domain>.com/foo,bar
- Don’t include trailing commas:
http://<domain>.com/foo, other text
- Detect spaces (paths are ambiguous?)
c:\Users\X\My Documents
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:21 (18 by maintainers)
Top Results From Across the Web
A Guide To Parsing: Algorithms And Terminology
An in-depth coverage of parsing terminology an issues, together with an explanation for each one of the major algorithms and when to use...
Read more >Detect URLs in text with JavaScript - regex - Stack Overflow
First you need a good regex that matches urls. This is hard to do. See here, here and here: ...almost anything is a...
Read more >Parse a sentence
The parser expects just one sentence. It will try to analyze what you put into the box as a single sentence. We recommend...
Read more >Practical parsing with Flex and Bison - begriffs.com
We just need to pair it with a scanner that reads atoms and parens. Finally, here's how to call the parser from a...
Read more >Parsing sentences with the OTHER natural language tool
Jeff ElmoreMany of you are probably familiar with NLTK, the wonderful Natural Language Toolkit for Python. You may not be familiar with ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Current state
The way links work right now is that after the viewport has stopped scrolling for 200ms, the links are computed for the current viewport. Embedders can provide a validation callback which allows the embedder to validate the link sometime after the links are computed, note that links are only shown once they are validated. The end result is pretty nice, we can present underlines for all links even when you need a modifier to execute the link, it does however have some fundamental problems:
Proposal
The long standing hope was to move to a “parser-based” link system (https://github.com/xtermjs/xterm.js/issues/583) but it was never really clear how an addon would provide a parser exactly. Here’s my very VS Code API-inspired proposal:
The basic idea is that instead of evaluating links whenever scrolling has stopped, only evaluate links for the current cursor position when a hover occurs. While file access is slow en masse, single requests just for mouse movement should be reasonable. Some other things of interest:
IBufferRange
or use a parser to check the whole line, or just expand outwards from the cursor.Going this route would seemingly fix many of the problems VS Code has with links, namely:
The only downside for this is a slight delay in the link appearing as the computing and validation occurs at hover time.
Open questions
ILinkMatcherOptions.priority
equivalent?Promise
into the API, working with promises is lovely but we will always have callbacks in the parser for performance reasons. We could just stick to the callback everywhere for consistency?Not sure if I’ll have time to get to this in the next couple of months so this is open to PRs if someone want to have a go at implementing a proof of concept. I think we’ll want to support both links types until the next major version at which point
registerLinkMatcher
will get removed.