Giter Site home page Giter Site logo

c# not work about neogen HOT 8 CLOSED

CRAG666 avatar CRAG666 commented on August 17, 2024
c# not work

from neogen.

Comments (8)

danymat avatar danymat commented on August 17, 2024

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

from neogen.

danymat avatar danymat commented on August 17, 2024

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

from neogen.

MikaelElkiaer avatar MikaelElkiaer commented on August 17, 2024

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

from neogen.

danymat avatar danymat commented on August 17, 2024

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

from neogen.

MikaelElkiaer avatar MikaelElkiaer commented on August 17, 2024

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.

from neogen.

danymat avatar danymat commented on August 17, 2024

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

from neogen.

MikaelElkiaer avatar MikaelElkiaer commented on August 17, 2024

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.

from neogen.

MikaelElkiaer avatar MikaelElkiaer commented on August 17, 2024

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

from neogen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.