I noticed that text object queries are not supported by ocaml-lsp-server.
❯ hx --health ocaml
Configured language servers:
✓ ocamllsp: /Users/joel/.opam/5.2.0+ox/bin/ocamllsp
Configured debug adapter: None
Configured formatter: ocamlformat
Binary for formatter: /Users/joel/.opam/5.2.0+ox/bin/ocamlformat
Tree-sitter parser: ✓
Highlight queries: ✓
Textobject queries: ✘
Indent queries: ✓
What does it take to add them?
Helix’ “text object queries” aren’t a LSP thing (or they use a strange name for some LSP feature Specification ), but a Treesitter feature that has to be added to Helix itself, if I understand this page Adding textobject queries correctly
I don’t think that’s the case. Same Helix gives me the ability to select a type, function, etc. with Zig.
❯ hx --health zig
Configured language servers:
✓ zls: /opt/homebrew/bin/zls
Configured debug adapter: lldb-dap
Binary for debug adapter: /opt/homebrew/opt/llvm/bin/lldb-dap
Configured formatter: zig
Binary for formatter: /opt/homebrew/bin/zig
Tree-sitter parser: ✓
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓
Here is the textobjects.scm
file for zig in the Helix source:
(function_declaration
body: (_) @function.inside) @function.around
(test_declaration (_) (block) @test.inside) @test.around
; matches all of: struct, enum, union
; this unfortunately cannot be split up because
; of the way struct "container" types are defined
(variable_declaration (identifier) (struct_declaration
(_) @class.inside)) @class.around
(variable_declaration (identifier) (enum_declaration
(_) @class.inside)) @class.around
(variable_declaration (identifier) (enum_declaration
(_) @class.inside)) @class.around
(parameters
((_) @parameter.inside . ","? @parameter.around) @parameter.around)
This file has been truncated. show original
whereas for Ocaml it is missing: helix/runtime/queries/ocaml at 1491cbc8f3694e52a565d192eaef1a7bf200d33f · helix-editor/helix · GitHub
1 Like
Text objects are a Helix feature, not an LSP one, and they require a tree-sitter grammar (ugh) and tree-sitter queries file for language-specific support.
Mea culpa!
I’ll add it to my list of OCaml-related things to fix.
1 Like
I tried to add some to a similar neovim projects nvim-treesitter-textobjects/queries/ocaml/textobjects.scm at master · nvim-treesitter/nvim-treesitter-textobjects · GitHub .
I’m far from a treesitter expert, so I expect things can be done better, but it’s starting point.
2 Likes