vscode: Completion doesn't correctly use prefix
Does this issue occur when all extensions are disabled?: No. The behavior requires completion with a language server.
- VS Code Version: 1.86.1
- OS Version: Linux x64 6.7.4-arch1-1
Steps to Reproduce:
- Take a language that allows ‘-’ in identifiers. The
editor.wordSeparatorsare set to:"editor.wordSeparators": "~!@#$%^&*()=+[{]}\\|;:'\",.<>/?". Note that “-” is not in the list. (For the issue I also removed the back-tick since it interfered with markdown). - Create a language server that returns “foo-bar” as completion.
- Write ‘foo-’ then trigger the completion. The LSP server provides “foo-bar”, but the editor doesn’t recognize the existing prefix and adds the suggested “foo-bar” in its entirety, leading to “foo-foo-bar”.
Screenshots:
- Good case: completion is triggered after the first “f”, and then I typed “oo-”. Vscode correctly uses the suggested foo-bar and matches it with the prefix.
- Bad case: completion is triggered after the “-”. Vscode uses the suggested foo-bar, but doesn’t match it with the prefix. If the completion was used it would yield foo-foo-bar.
- Good case: completion is triggered after ‘foo-b’. This time Vscode correctly uses the existing prefix.
So it seems like being at the ‘-’ (which is not a word-separator) confuses vscode and it doesn’t match the existing prefix anymore.
This comment seems related, but is probably hitting something else: https://github.com/microsoft/vscode/issues/188162#issuecomment-1645732528
Edit:
as @RedCMD determined, the issue is that the word-pattern for the language doesn’t recognize foo- as word. However, the default range for a CompletionItem is using the getWordRangeAtPosition.
See https://github.com/microsoft/vscode/blob/133b4e591c6e14847b775ddf8c8478d8d619fc23/src/vs/editor/common/languages.ts#L505 and https://github.com/microsoft/vscode/blob/133b4e591c6e14847b775ddf8c8478d8d619fc23/src/vs/editor/contrib/suggest/browser/suggest.ts#L225 (and the setting of the range field in line 247).
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (6 by maintainers)
I would think
"wordPattern"inlanguage-configuration.jsonis partially at fault