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

c# not work #62

Closed
CRAG666 opened this issue Feb 2, 2022 · 8 comments · Fixed by #89
Closed

c# not work #62

CRAG666 opened this issue Feb 2, 2022 · 8 comments · Fixed by #89
Labels
under review Waiting for review by users or developer.

Comments

@CRAG666
Copy link

CRAG666 commented Feb 2, 2022

A few days ago I could use it with C# but after updating it doesn't work it tells me that "Language cs not supported."

@danymat
Copy link
Owner

danymat commented Feb 2, 2022

Hmm, weird
It should have said csharp instead..
Can you go on a csharp file and print :lua print(vim.no.filetype) ?

@danymat danymat added the bug Something isn't working label Feb 2, 2022
@danymat danymat closed this as completed in 271260c Feb 2, 2022
@danymat
Copy link
Owner

danymat commented Feb 2, 2022

Hello, indeed the new Neogen internals require the filename to be exactly the result of filetype, can you try it out ?

@danymat danymat added under review Waiting for review by users or developer. and removed bug Something isn't working labels Feb 2, 2022
@MikaelElkiaer
Copy link
Contributor

MikaelElkiaer commented Apr 27, 2022

@danymat Late ping, sorry, was unsure whether this would go unnoticed as the issue is closed.

There seems to be another problem related to this.

I get the following error with the latest version:

E5108: Error executing lua /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:25: no parser for 'cs' language, see :help treesitter-parsers
stack traceback:
        [C]: in function 'error'
        /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:25: in function 'require_language'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:39: in function '_create_parser'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:94: in function 'get_parser'
        ...m/site/pack/packer/start/neogen/lua/neogen/generator.lua:41: in function 'get_parent_node'
        ...m/site/pack/packer/start/neogen/lua/neogen/generator.lua:206: in function 'generate'
        [string ":lua"]:1: in main chunk

So it correctly finds a configuration based on the cs filetype. But it directly uses that to look up the TreeSitter parser - which is called c_sharp.
Perhaps something has changed with vim.treesitter.get_parser as used here:

local parser = vim.treesitter.get_parser(0, filetype)

Trying it out with lua print(vim.treesitter.get_parser(0, "c_sharp")) I get a result, but not for lua print(vim.treesitter.get_parser(0, "cs")).

@danymat danymat reopened this Apr 27, 2022
@danymat
Copy link
Owner

danymat commented Apr 27, 2022

Hello, can you try again with latest commit ? 32adfde

@MikaelElkiaer
Copy link
Contributor

Hello, can you try again with latest commit ? 32adfde

I did try renaming myself, but it only moved the problem, as it then cannot match the filetype with a neogen configuration:

E5108: Error executing lua ...m/site/pack/packer/start/neogen/lua/neogen/generator.lua:201: attempt to index field 'parent' (a nil value)
stack traceback:
        ...m/site/pack/packer/start/neogen/lua/neogen/generator.lua:201: in function 'generate'
        [string ":lua"]:1: in main chunk

So, nvim filetype is cs, while treesitter parser filetype is c_sharp.

It works if I keep the keep the file named lua/neogen/configurations/cs.lua and then do a simple mapping before getting the parser:

diff --git a/lua/neogen/generator.lua b/lua/neogen/generator.lua
index b762176..a4f2cc8 100644
--- a/lua/neogen/generator.lua
+++ b/lua/neogen/generator.lua
@@ -38,7 +38,8 @@ local function todo_text(type)
 end

 local function get_parent_node(filetype, typ, language)
-    local parser = vim.treesitter.get_parser(0, filetype)
+    local parser_name = filetype == "cs" and "c_sharp" or filetype
+    local parser = vim.treesitter.get_parser(0, parser_name)
     local tstree = parser:parse()[1]
     local tree = tstree:root()

I do wonder how this worked earlier. Perhaps vim.treesitter.get_parser has changed? It is a little unclear that its parameter filetype refers to a name known to treesitter which does not necessarily correspond to the nvim filenameg.

@danymat
Copy link
Owner

danymat commented Apr 27, 2022

Very weird, nvim-treesitter has likely changed the name in fact.
Do you want to create a PR for that (revert the file change, and apply the patch) ? I'm not at home at the moment, so i can not do it for the next hours

@MikaelElkiaer
Copy link
Contributor

Very weird, nvim-treesitter has likely changed the name in fact. Do you want to create a PR for that (revert the file change, and apply the patch) ? I'm not at home at the moment, so i can not do it for the next hours

I'm using the patch locally for now, so no rush. I might do a PR if I can come up with a bit more generic way of handling the mapping from filetype to treesitters parser name.

@MikaelElkiaer
Copy link
Contributor

@danymat I found out how to do the mapping and added a PR #89.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under review Waiting for review by users or developer.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants