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

WIP: HTML support #43

Closed
wants to merge 4 commits into from
Closed

WIP: HTML support #43

wants to merge 4 commits into from

Conversation

KostkaBrukowa
Copy link
Collaborator

This is VEEERY early stage. For now the diagnostics works very well. I've written one of the handler to show you the idea and see what you think.

Things to do:

  • finish all of the TODO-s
  • find and fix all of the broken lsp handlers
  • tests
  • experimental configuration to enable this feature

#36

Screen.Recording.2023-06-02.at.22.26.46.mov

for character_index = 1, #line do
local is_position_in_script = false

for _, script_range in ipairs(scripts_ranges) do
Copy link
Owner

@pmizio pmizio Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposition is to map script ranges per lines to easly eliminate non js lines without additional iterations eg:

local scripts_ranges = {
  -- line 1
  [1] = {range1, ...rangeN},
  -- line n
  [n] = {rangeN, ...rangeM}
}

with this you can safetly and fast determine lines to "emptify" without iterating over all ranges for every line

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When line number isn't in scripts_ranges just fast forward to emptify line. Otherwise try to monkeypatch line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reversed the logic and now I'm emptying everything and then insert chars from script tags. I think it will be faster

lua/typescript-tools/protocol/html_support.lua Outdated Show resolved Hide resolved
lua/typescript-tools/protocol/html_support.lua Outdated Show resolved Hide resolved
lua/typescript-tools/tsserver.lua Outdated Show resolved Hide resolved
@pmizio
Copy link
Owner

pmizio commented Jun 4, 2023

I posted few ideas how to squeeze more performance and hopefully slimplify code

@KostkaBrukowa KostkaBrukowa changed the base branch from feature/rebuild-of-plugin to master June 7, 2023 18:35
@KostkaBrukowa
Copy link
Collaborator Author

FYI I've actually resigned from creating separate buffer for script content. Now I'm only rewriting didChange and didOpen requests for HTML document and it seems to be working very well

@marlun
Copy link

marlun commented Jul 21, 2023

Just wanted to try this out so I selected the feat-embedded-languages branch with Packer but even though typescript@5.1.6 and typescript-language-server@3.3.2 is installed globally I'm getting this when starting neovim:

|| [lspconfig] unhandled error: ...pt-tools.nvim/lua/typescript-tools/tsserver_provider.lua:61: Cannot find tsserver executable in local project nor global npm installation.

@KostkaBrukowa
Copy link
Collaborator Author

KostkaBrukowa commented Jul 24, 2023

@marlun it was very old branch, but I've merged master into in and you can check if it helped. In the past there were some issues about finding typescript exetutable, but they were fixed
Also I will add it is very work-in-progress branch and honestly I don't know what will be the future of this branch

@KostkaBrukowa KostkaBrukowa marked this pull request as draft July 24, 2023 09:59
@marlun
Copy link

marlun commented Jul 24, 2023

Thanks, I'm no longer getting that error. I'm not sure if you want feedback on this, tell me otherwise.

Now when I hit K I'm getting:

Error executing vim.schedule lua callback: ...ools.nvim/lua/typescript-tools/protocol/html_support.lua:20: bad argument #1 to 'unpack' (table expected, got number)                                           
stack traceback:
        [C]: in function 'unpack'
        ...ools.nvim/lua/typescript-tools/protocol/html_support.lua:20: in function 'is_position_between_range'
        ...ools.nvim/lua/typescript-tools/protocol/html_support.lua:189: in function 'handler'
        ...r/neovim/HEAD-ca9f4a7/share/nvim/runtime/lua/vim/lsp.lua:1497: in function 'cb'
        vim/_editor.lua:324: in function <vim/_editor.lua:323>

My code looks like this and my cursor is on document when I hit K:

    <script>
      const input = document.querySelector("input");
    </script>

@pmizio pmizio closed this Oct 2, 2023
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

Successfully merging this pull request may close these issues.

3 participants