ide-typescript
ide-typescript copied to clipboard
Support embedded scopes and scripts
This is an html file.
http://nimb.ws/nSAGx4
Could it be that the getSuggestions logic continues , seeing as though the server is still awaiting... and hasn't had a chance to become null ?
I've put logic into the 0.1.6 update that just went out to avoid the null error - are you using that version or the older one?
For non-JS/TS files getSuggestions should never be called because of this https://github.com/atom/atom-languageclient/blob/master/lib/auto-languageclient.js#L199 so open to ideas on how it's getting there. 😕
Does the HTML file have script tags? Maybe it's picking up on the embedded JS scopes?
It's possible. The activation grammar checking is based on the top scope of the file - I'm not sure what autocomplete does but it's quite possible it's scope based.
The fix that went out should stop the error but there is a larger open question of how LSP deals with scopes and blocks that I haven't seen any answers for. Is a javascript language server expected to be able to deal with html files?
Yes it does, have script tag, however in the default scopes in main.js getGrammars, source.embedded.html.js is not there. That was a suggestion in a previous ticket I submitted. However that is currently not in place so it shouldn't be the case here.
Hmm @damieng I wonder if the conditional should happen sooner than within getSuggestions ? Seeing as though in the languageClient we would have already called getSuggestions at this point.
Running JS IDE features in inline scripts is very useful for webcomponent developers
The language server protocol is not clear on what to do about embedded scripts or scopes. Any pointers would be great! :)
vscode has an html language server as well as ts/js. I'm curious as to how they might be implementing the implementing the inline intellisense. It could be that they are casting the script block as a virtual js file, then using that as a source of reference. But that is a very wild theory atm.
I'll try to look further if you guys want to collect your findings here as well.
How to solve the HTML inline
see VSCode: extensions/html/client/src/htmlMain.ts#L52
Where VSCode's HTML extension defines javascript as an embeddedLanguage
and see VSCode: src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts#L389 Where it looks like they're parsing linewise, and if they find javascript, they activate the JS grammar
Is this enough to put together an initial PR? @rwatts3 what do you think?
@bennypowers That covers the activation which I think we could implement. The confusion is whether the typescript language server will be happy receiving HTML files. We could try it and see as the language server protocol has no mention of embedded scripts.
I wonder if at that point if the lsp has already received the contents of the line ? Would it care about the file at that point. Or if there is anyway we can bypass the file part.