claytonrcarter / tree-sitter-phpdoc

PHPDoc grammar for tree-sitter
22 stars 10 forks source link

Cannot install on macOS arm64 due to outdated CLI version #15

Closed wookayin closed 1 year ago

wookayin commented 2 years ago

I ran into an error saying npm ERR! Error: Cannot install tree-sitter-cli for architecture arm64 (https://github.com/tree-sitter/tree-sitter/issues/942) while installing tree-sitter-phpdoc.

This is because of tree-sitter-cli version is set to ^0.17.3 -- The issue has been fixed in tree-siter-cli v0.18.3+. Can you update the dependency version so that I can install the module on a arm64 mac? Thanks!

mikehaertl commented 2 years ago

See the discussion here for why an update is still postponed: https://github.com/claytonrcarter/tree-sitter-phpdoc/pull/2

claytonrcarter commented 2 years ago

Yes, @mikehaertl is correct. That said, I understand that the latest TS (0.20.3 or .4) allows us to generate parsers for arbitrary ABIs. I'll try to play with this to see if we can update to latest TS but then commit the older ABI parsers for use on npm and Atom. That way, anyone could get the latest version as well, just by doing something like npm install tree-sitter-phpdoc ; ./node_modules/.bin/tree-sitter generate

claytonrcarter commented 2 years ago

allows us to generate parsers for arbitrary ABIs

Turns out this is not true. It only supports ABIs 13 and 14, both of which are "newer" than what I can use for my OG use case. Until Atom gets updated tree-sitter support, we either need to make sure that this parser works w/ newer tree-sitter versions, or that it can be downgraded and still work for older versions. Either way, it's a PITA. FWIW, I've just confirmed that this works as-is w/ the the latest tree-sitter: npm i tree-sitter-cli@\* ; ./node_modules/.bin/tree-sitter generate ; ./node_modules/.bin/tree-sitter test. Thanks for your patience and understanding.

anoxia commented 2 years ago

Quick fix: install tree-sitter-phpdoc under macOS arm chip

Principle: Hack customization of nvim-treesitter.

Note: I use LunarVim, please hack according to your actual situation

Steps:

Go to the nvim-treesitter directory:

cd ~/.local/share/lunarvim/site/pack/packer/start/

Modify the file lua/nvim-treesitter/parsers.lua by referring to the following code

list.phpdoc = {
  install_info = {
-    url = "https://github.com/claytonrcarter/tree-sitter-phpdoc",
+    url = "https://github.com/Anoxia/tree-sitter-phpdoc",
    files = { "src/parser.c", "src/scanner.c" },
    -- parser.c in the repo still based on TS 0.17 due to other dependencies
    requires_generate_from_grammar = true,
    generate_requires_npm = true,
  },
  maintainers = { "@mikehaertl" },
  experimental = true,
}

Modify lockfile.json file

   "phpdoc": {
-    "revision": "46d6366a66266f1e9ae00ee7ea27aa9de629ade6"
+    "revision": "cc4a3da3089e58cf037dc6675b01c41f08143b53"
   },

Finally, reload the nvim configuration, install phpdoc via TSInstall phpdoc, and if the parser.so file fails to move, execute the following command:

cp ~/.local/share/nvim/tree-sitter-phpdoc/parser.so ~/.local/share/lunarvim/site/pack/packer/start/nvim-treesitter/parser/phpdoc.so

enjoy😊!

oxfist commented 1 year ago

Came into this great answer and wanted to provide a more general version of the last comment's solution, in case you have installed a regular version of Neovim instead of LunarVim (Neovim vs LunarVim):

1. Go to plugins path

Default Neovim path:

cd ~/.local/share/nvim/site/pack/packer/start/

2. Modify nvim-treesitter/lua/nvim-treesitter/parsers.lua

list.phpdoc = {
  install_info = {
-    url = "https://github.com/claytonrcarter/tree-sitter-phpdoc",
+    url = "https://github.com/Anoxia/tree-sitter-phpdoc",
    files = { "src/parser.c", "src/scanner.c" },
    -- parser.c in the repo still based on TS 0.17 due to other dependencies
    requires_generate_from_grammar = true,
    generate_requires_npm = true,
  },
  maintainers = { "@mikehaertl" },
  experimental = true,
}

3. Modify nvim-treesitter/lockfile.json

   "phpdoc": {
-    "revision": "46d6366a66266f1e9ae00ee7ea27aa9de629ade6"
+    "revision": "cc4a3da3089e58cf037dc6675b01c41f08143b53"
   },

4. Reload Neovim and Install phpdoc

Re-open Neovim to reload configuration, then install parser:

:TSInstall phpdoc
qRoC commented 1 year ago
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()

-- Fix `Cannot install tree-sitter-cli for architecture arm64`
parser_config.phpdoc.install_info.url = "https://github.com/Anoxia/tree-sitter-phpdoc"

require("nvim-treesitter.configs").setup {
  ...
}

And remove lockfile.json

anoxia commented 1 year ago

Came into this great answer and wanted to provide a more general version of the last comment's solution, in case you have installed a regular version of Neovim instead of LunarVim (Neovim vs LunarVim):

1. Go to plugins path

Default Neovim path:

cd ~/.local/share/nvim/site/pack/packer/start/

2. Modify nvim-treesitter/lua/nvim-treesitter/parsers.lua

list.phpdoc = {
  install_info = {
-    url = "https://github.com/claytonrcarter/tree-sitter-phpdoc",
+    url = "https://github.com/Anoxia/tree-sitter-phpdoc",
    files = { "src/parser.c", "src/scanner.c" },
    -- parser.c in the repo still based on TS 0.17 due to other dependencies
    requires_generate_from_grammar = true,
    generate_requires_npm = true,
  },
  maintainers = { "@mikehaertl" },
  experimental = true,
}

3. Modify nvim-treesitter/lockfile.json

   "phpdoc": {
-    "revision": "46d6366a66266f1e9ae00ee7ea27aa9de629ade6"
+    "revision": "cc4a3da3089e58cf037dc6675b01c41f08143b53"
   },

4. Reload Neovim and Install phpdoc

Re-open Neovim to reload configuration, then install parser:

:TSInstall phpdoc

This path does not exist on my machine:

cd ~/.local/share/nvim/site/pack/packer/start/
oxfist commented 1 year ago

@Anoxia happy to help if you can provide more information about your setup.

Do you use packer and have tree-sitter installed? Do you have LunarVim installed or regular Neovim?

anoxia commented 1 year ago

@Anoxia happy to help if you can provide more information about your setup.

Do you use packer and have tree-sitter installed? Do you have LunarVim installed or regular Neovim?

I use LunarVim. Sorry, I thought everyone used LunarVim, so I mistook the path you provided for a problem.

amitkot commented 1 year ago

@claytonrcarter would it be possible to include this change in this repo as well?

claytonrcarter commented 1 year ago

For those interested (looking at you, @amitkot, and others), please take a look at #23 and let me know if just upgrading to the latest version tree-sitter works for you. Thanks!

claytonrcarter commented 1 year ago

Thank you all for your patience. This repo is using the latest version (at this time) of tree-sitter as of 592429e4846ad269b74683ef5a399003e210a644, so all of this rigamarole should be no longer necessary.