I find that vscode does really good url extraction, better than any methods found in the internet. Since vscode is opensource, where can I find the code? Probably regex rules. shortcut for nice url extraction result
I searched the source code with keyword "url" or "extract", but can not find any clues.
2
Answers
vscode uses ripgrep under the hood. You can find more information about the implementation here https://github.com/BurntSushi/ripgrep
For the builtin link detection
Not 100% percent sure that this is it, but from my search through the source code, I think you might be looking for
src/vs/editor/common/languages/linkComputer.ts
, which uses a state-machine-based approach.You can see in
src/vs/editor/browser/services/editorWorkerService.ts
, inEditorWorkerService
‘s constructor, there’s a comment saying "register default link-provider and default completions-provider
", and a call toclient.computeLinks
, which is defined insrc/vs/editor/common/services/editorSimpleWorker.ts
in theEditorSimpleWorker
class’computeLinks
function, which in turn callscomputeLinks
fromlinkComputer.ts
. That comment lines up nicely with the description ofDocumentLinkProvider<T>
‘sprovideDocumentLinks
function, which states:Fun fact: you can find where it’s used in https://github.com/search?q=repo%3Amicrosoft%2Fvscode%20computeLinks&type=code, including
src/vs/workbench/contrib/output/common/outputLinkComputer.ts
andsrc/vs/workbench/contrib/terminalContrib/links/browser/terminalUriLinkDetector.ts
.For extension-contributed link "detection"
As mentioned above, there’s the
DocumentLinkProvider
extension API that extension can use to contribute links to documents. If you want to find out how a specific extension is doing that, you’ll need to post a question specifically about that extension.