ide-typescript icon indicating copy to clipboard operation
ide-typescript copied to clipboard

Support embedded scopes and scripts

Open romans127 opened this issue 8 years ago • 12 comments

This is an html file.

http://nimb.ws/nSAGx4

romans127 avatar Aug 23 '17 17:08 romans127

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 ?

romans127 avatar Aug 23 '17 17:08 romans127

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. 😕

damieng avatar Aug 23 '17 17:08 damieng

Does the HTML file have script tags? Maybe it's picking up on the embedded JS scopes?

winstliu avatar Aug 23 '17 17:08 winstliu

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?

damieng avatar Aug 23 '17 17:08 damieng

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.

romans127 avatar Aug 23 '17 17:08 romans127

Running JS IDE features in inline scripts is very useful for webcomponent developers

bennypowers avatar Sep 12 '17 19:09 bennypowers

The language server protocol is not clear on what to do about embedded scripts or scopes. Any pointers would be great! :)

damieng avatar Sep 12 '17 19:09 damieng

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.

romans127 avatar Sep 12 '17 20:09 romans127

How to solve the HTML inline

zhangsiyi avatar Nov 23 '17 03:11 zhangsiyi

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 avatar Jan 02 '18 08:01 bennypowers

@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.

damieng avatar Jan 02 '18 15:01 damieng

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.

romans127 avatar Jan 09 '18 18:01 romans127