CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
208 stars 29 forks source link

Default search service extension - follow file link doesn't work #371

Closed Abdallatif closed 3 months ago

Abdallatif commented 3 months ago

When using the @codingame/monaco-vscode-search-result-default-extension and open search results in editor, then hover over a file name and click on the follow link

image

The following error appears:

image

In the console, it shows the following error:

Uncaught (in promise) Error: Unable to read file '/test.js' (Error: Unable to resolve nonexistent file '/test.js')
    at VHe.restoreReadError (main.common-7DLNmK_d.js:1427:23935)
    at VHe.doReadFileStream (main.common-7DLNmK_d.js:1427:23642)
    at async WHe.doRead (main.common-7DLNmK_d.js:1427:78870)
    at async WHe.readStream (main.common-7DLNmK_d.js:1427:78625)
    at async ame.resolveFromFile (main.common-7DLNmK_d.js:1427:57239)
    at async ame.resolve (main.common-7DLNmK_d.js:1427:55401)
    at async FHe.doResolve (main.common-7DLNmK_d.js:1427:73374)
    at async sKe.doCreateReferencedObject (main.common-7DLNmK_d.js:1734:6398)
    at async Xjt.acquire (main.common-7DLNmK_d.js:29:3253)
    at async oKe.createModelReference (main.common-7DLNmK_d.js:1734:8629)

I tried to do some debugging and find the core issue, my guess here is that the ~ is being ignored while it should be converted to the workspace uri.

I also found (by manually changing the editor search results) that if we remove the ~/ from the file path, vscode would be able to locate the file correctly.

CGNonofr commented 3 months ago

Thanks for the report!

Once again, it's a bug in VSCode (or a combination of bugs) that doesn't affect VScode in the way it's used but does impact monaco-vscode-api

Explanation:

So, in the demo, the user home directory is detected by VSCode as /tmp while it's detected as / by the search result extension

It works in VSCode.dev because there is no way to start with a local open folder (you can only open it later)

So a workaround can be to do the same as in vscode.dev: create an empty workspace THEN add your folder in it when the services are initialized

CGNonofr commented 3 months ago

https://github.com/CodinGame/monaco-vscode-api/pull/373 will allow to manually configure user home directory, setting it to anything else (/ is fine) will workaround your issue

Abdallatif commented 3 months ago

Awesome, thanks a lot for fixing this 🙏 I'll close the issue since it's fixed now.