TerminalFi / LSP-copilot

GitHub Copilot support for Sublime Text LSP plugin provided through Copilot.vim.
625 stars 25 forks source link

fix: wrong syntax highlighting for embedded languages #34

Closed jfcherng closed 1 year ago

jfcherng commented 1 year ago

Fixes https://github.com/TheSecEng/LSP-copilot/issues/33


For example, syntax highlighting for completing JS codes inside Markdown fenced code block.

image

The main idea is to get the deepest/last source | text | embedding scope and find the languageId for it.

For the example above, the scope at the cursor is text.html.markdown markup.raw.code-fence.javascript.markdown-gfm source.js. We should take source.js for resolving languageId rather than text.html.markdown.

jfcherng commented 1 year ago

Unfortunately, this won't work for PHP.

image

Python 3.3>>> from LSP.plugin.core.types import basescope2languageid
Python 3.3>>> basescope2languageid('source.php.embedded.html')
'html'
jfcherng commented 1 year ago

I notice that

So I assume that we have a scoping convention for embedded things: EMBEDDED_LANG.embedded.PARENT_LANG. Hence we can extract EMBEDDED_LANG, which we are interested in.

jfcherng commented 1 year ago

Looks good again.

image