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

The plugin does not always interpret correctly )} in Lua #78

Closed
ChrisGVE opened this issue Jan 2, 2025 · 9 comments · Fixed by #79
Closed

The plugin does not always interpret correctly )} in Lua #78

ChrisGVE opened this issue Jan 2, 2025 · 9 comments · Fixed by #79

Comments

@ChrisGVE
Copy link

ChrisGVE commented Jan 2, 2025

Most of the time, the plugin works great, but I have encountered what is probably a border case where it does not show the context correctly:

image

This comes from a wezterm configuration file (which is partially supported by the LSP, especially when using plugins).

I'm happy to help you debug it, but I would need some directions.

@andersevenrud
Copy link
Owner

You can use the command :NvimContextVtDebug to print out some information you can paste here. That might help find a solution :)

https://github.com/andersevenrud/nvim_context_vt?tab=readme-ov-file#debug

@ChrisGVE
Copy link
Author

ChrisGVE commented Jan 2, 2025

Cool thanks for the quick reply, here is the output

   907:chunk --> ---------
509:table_constructor --> {
509:arguments --> ({
509:function_call --> resurrect.periodic_save({

andersevenrud added a commit that referenced this issue Jan 2, 2025
@andersevenrud
Copy link
Owner

I was a little bit unsure about what was missing here, but did a quick test and found the following:

In JavaScript

foo.bar({
    a: b,
    c: d,
}) --> foo.bar({

In Lua

foo.bar({
    a = b,
    c = d,
}) --> ({

local foo = foo.bar({
    a = b,
    c = d,
}) --> local foo = foo.bar

I created a potential fix for this here: #79

Let me know if it works out :)

@ChrisGVE
Copy link
Author

ChrisGVE commented Jan 2, 2025

I've applied the fix manually, but unfortunately I still have the same result.

However, I am getting something different now with the debug, to recap:
image
(showing again as I made some changes, so line # are not the same as above)

and here is the debug output

16:45:02 msg_show   NvimContextVtDebug    517:table_constructor --> {
16:45:02 msg_show   NvimContextVtDebug    517:arguments --> ({
16:45:02 msg_show   NvimContextVtDebug    517:function_call --> resurrect.set_encryption({
16:45:02 msg_show   NvimContextVtDebug 907:chunk --> ---------

Well, maybe not so much change after all... just line #

@ChrisGVE
Copy link
Author

ChrisGVE commented Jan 2, 2025

Ok I went into Treesitter and here is the tree for the function above:

  (function_call ; [504, 0] - [509, 2]
    name: (dot_index_expression ; [504, 0] - [504, 23]
      table: (identifier) ; [504, 0] - [504, 9]
      field: (identifier)) ; [504, 10] - [504, 23]
    arguments: (arguments ; [504, 23] - [509, 2]
      (table_constructor ; [504, 24] - [509, 1]
        (field ; [505, 1] - [505, 23]
          name: (identifier) ; [505, 1] - [505, 17]
          value: (number)) ; [505, 20] - [505, 23]
        (comment ; [505, 25] - [505, 29]
          content: (comment_content)) ; [505, 27] - [505, 29]
        (field ; [506, 1] - [506, 22]
          name: (identifier) ; [506, 1] - [506, 15]
          value: (true)) ; [506, 18] - [506, 22]
        (field ; [507, 1] - [507, 19]
          name: (identifier) ; [507, 1] - [507, 12]
          value: (true)) ; [507, 15] - [507, 19]
        (field ; [508, 1] - [508, 17]
          name: (identifier) ; [508, 1] - [508, 10]
          value: (true))))) ; [508, 13] - [508, 17]

I hope it helps

@andersevenrud
Copy link
Owner

andersevenrud commented Jan 2, 2025

Thanks!

Sorry for premature closing of issue. I've just pushed another commit that might fix the issue.


My initial PR seemed to work fine on my end on initial testing, but it turned out that the ts structure changed when there's a root return statement (module pattern).

I believe I have added the correct context keyword now.

@andersevenrud andersevenrud reopened this Jan 2, 2025
@ChrisGVE
Copy link
Author

ChrisGVE commented Jan 2, 2025

Cool, indeed it is fixed with the last PR. Thanks a lot for the swift action!

@ChrisGVE
Copy link
Author

ChrisGVE commented Jan 2, 2025

Fixed

@ChrisGVE ChrisGVE closed this as completed Jan 2, 2025
@andersevenrud
Copy link
Owner

Awesome :)

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 a pull request may close this issue.

2 participants