Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does code completion work differently for different languages? #93

Open
donaldpipowitch opened this issue Sep 5, 2018 · 12 comments
Open
Assignees

Comments

@donaldpipowitch
Copy link
Contributor

I changed the actionEvent in the lsp-sample from"onLanguage:plaintext" (see here) to "onLanguage:json"/"onLanguage:jsonc" and opened a JSON file. I tried to write T or J somewhere to get autocompletion for TypeScript or JavaScript just as in the case of the plain text file, but it seems that the onCompletion callback is never called.

Is this a bug or a different languages treated differently? What should I need to do to get auto completion for other languages? I couldn't find something specific about this in the docs.

@KamasamaK
Copy link
Contributor

The activationEvents are just for when the extension is activated and unrelated to LSP. What determines whether the language features (like completion) are triggered is documentSelector.

@donaldpipowitch
Copy link
Contributor Author

Thank you so much for the explanation! 😍

@donaldpipowitch
Copy link
Contributor Author

Not sure, if I still do something wrong. I added this and it still doesn't seem to add code completion to JSON files.

documentSelector: [
    { scheme: 'file', language: 'plaintext' },
    { scheme: 'file', language: 'json' },
    { scheme: 'file', language: 'jsonc' }
],

@donaldpipowitch
Copy link
Contributor Author

donaldpipowitch commented Sep 7, 2018

Update: It looks like on-type code completion works outside of comments, string values and properties. Completions with Ctrl+Space seem to work everywhere. Any idea why?

@KamasamaK
Copy link
Contributor

KamasamaK commented Sep 7, 2018

When in comments and strings, the default in VS Code is that only triggerCharacters and manually triggering (via Ctrl+Space) work to trigger a completion. You can change this default with the editor.quickSuggestions setting.

@donaldpipowitch
Copy link
Contributor Author

Thank! I'll try that out in the next days.

@donaldpipowitch
Copy link
Contributor Author

Okay, I tried editor.quickSuggestions.strings, but it doesn't seem to work for my use case?

{
  "foo": "Typ<doesn't auto complete to TypeScript here>"
}

@jrieken
Copy link
Member

jrieken commented Sep 10, 2018

That is specific problem with JSON - quick suggestions only work when typing at the end of a word and JSON defines " to be part of the word. cc @aeschli

@jrieken jrieken assigned aeschli and unassigned jrieken Sep 10, 2018
@aeschli
Copy link
Contributor

aeschli commented Sep 10, 2018

duplicate of microsoft/vscode#30811

@donaldpipowitch
Copy link
Contributor Author

When I understand microsoft/vscode#30811 correctly JSON treats " as the part of a word, right? So I tried this, but it doesn't seem to work?

{
-    label: 'TypeScript',
+    label: '"TypeScript',
    kind: CompletionItemKind.Text,
    data: 1
}

Is there some kind of workaround? 🤔

@aeschli
Copy link
Contributor

aeschli commented Sep 10, 2018

The point is that quick suggestions only pop up when at the end of a symbol (word).
For JSON

{
  "foo": "Typ|"
}

is not at the end of a symbol, but in the middle (" is also part of the symbol)

@donaldpipowitch
Copy link
Contributor Author

When I understand Microsoft/vscode#30811 correctly JSON treats " as the part of a word, right? So I tried this, but it doesn't seem to work?

I tried this again and now it actually seems to work 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants