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

emacs: handle specially-named tree-sitter grammars #383937

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

leungbk
Copy link
Member

@leungbk leungbk commented Feb 21, 2025


Recent revisions of Emacs HEAD have a new markdown-ts-mode. This change allows Emacs to detect the markdown-inline grammar; to confirm, notice that on the latest nixpkgs, trying markdown-ts-mode will yield:

funcall-interactively: Cannot load language definition: not-found, "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline: cannot open shared object file: No such file or directory", "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline.0: cannot open shared object file: No such file or directory", "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline.0.0: cannot open shared object file: No such file or directory", "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline.so: cannot open shared object file: No such file or directory", "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline.so.0: cannot open shared object file: No such file or directory", "/nix/store/10zfcxcjk6f5w0m5va009yddr2m5rqf6-emacs-packages-deps/lib/libtree-sitter-markdown-inline.so.0.0: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline.0: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline.0.0: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline.so: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline.so.0: cannot open shared object file: No such file or directory", "/home/brian/.config/emacs/tree-sitter/libtree-sitter-markdown-inline.so.0.0: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline.0: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline.0.0: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline.so: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline.so.0: cannot open shared object file: No such file or directory", "libtree-sitter-markdown-inline.so.0.0: cannot open shared object file: No such file or directory"

The underscores seem to be there solely to placate nvim-treesitter (4623212).

Fixes #348933.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@leungbk leungbk force-pushed the emacs-treesit-names branch from 5a30607 to 3f5ceb2 Compare February 21, 2025 13:35
@leungbk leungbk added the backport release-24.11 Backport PR automatically label Feb 21, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Feb 21, 2025
@jian-lin
Copy link
Contributor

The underscores seem to be there solely to placate nvim-treesitter (4623212).

I do not think this commit has anything to do the issue this PR tries to solve because withPlugins modified by that PR is not used here.

This PR indeed works. However, it looks more like an upstream (Emacs or markdown_inline tree-sitter) issue. Can it be reproduced without Nixpkgs? If so, it is better to report this issue to upstream and have it fixed there.

@leungbk
Copy link
Member Author

leungbk commented Feb 23, 2025

withPlugins modified by that PR is not used here.

OK, I don't think I explained the issue very well.

You're right that we're not using withPlugins here; my point in linking 4623212 was to stress that Neovim expects the LANG portion (and only that portion) of tree-sitter-LANG to have underscores instead of hyphens.

I should probably have linked #181195 (comment) instead, where language was explicitly set to be "markdown_inline" with an underscore (and not necessarily to placate Neovim).

I do not think this commit has anything to do the issue this PR tries to solve

In #348933, the OP noted However, some are missing, in particular libtree-sitter-markdown-inline.so does not appear., which this PR fixes; in the ls output he posted, he had only libmarkdown_inline.so (this since-merged #360388 would change that to libtree-sitter-markdown_inline.so, which would still not satisfy Emacs due to markdown-ts-mode's definition invoking (treesit-parser-create 'markdown-inline) with the hyphenated markdown-inline).

However, it looks more like an upstream (Emacs or markdown_inline tree-sitter) issue. Can it be reproduced without Nixpkgs?

The upstream naming markdown_inline seems to be intentional:

    {
      "name": "markdown_inline",
      "camelcase": "MarkdownInline",
      "scope": "text.markdown_inline",
      "path": "tree-sitter-markdown-inline",
      "highlights": "tree-sitter-markdown-inline/queries/highlights.scm",
      "injections": "tree-sitter-markdown-inline/queries/injections.scm",
      "external-files": [
        "common/common.js"
      ]
    }

For this reason, I would be hesitant to try and do something like changing our language name in nixpkgs from markdown_inline to something like markdown-inline.

The fact that Emacs expects the name libtree-sitter-markdown-inline.so with a hyphen instead of an underscore makes me suspect that Emacs users commonly install this grammar with a hyphen in its name, though I have evidence of this.

With all this in mind, do you currently prefer that we

a. go with something like the current PR or
b. ask Emacs upstream to invoke treesit-parser-create with the underscored name instead?

@jian-lin
Copy link
Contributor

jian-lin commented Feb 23, 2025

ask Emacs upstream to invoke treesit-parser-create with the underscored name instead

If it is indeed an upstream issue, i.e., it can be reproduced without Nixpkgs, then it would be good to report it to Emacs (and cc related people such as author of markdown-ts-mode and author of Emacs treesit infra).

go with something like the current PR

Even if it is an upstream issue, we probably should merge this PR now as a quick fix/workaround.


Thanks for those links. They are very helpful for me knowing little about tree sitter to get an overview for this.

@jian-lin jian-lin merged commit c6bcac5 into NixOS:master Feb 23, 2025
35 of 36 checks passed
@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented Feb 23, 2025

Successfully created backport PR for release-24.11:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: emacs Text editor 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux backport release-24.11 Backport PR automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

emacsPackages.treesit-grammars.with-all-grammars doesn't seem to build/link in all grammars
2 participants