Proposal: Syntax editing for program language

What

Use parser written in c/cpp, such as tree-sitter, to perform highlight and expansion of selection.

Why

  • Given language, current component of syntax highlight recognize its keyword only.
  • Structural editing for code is missing.

How

Prepared by community

An interface to load dynamic library, so that parser written in c can be loaded and imported from shared library. Shared library can be shipped in plugin.

Required work

  • Provide parser of language as plugin.
  • Import parser generated by tree-sitter as c source code.
  • Parse given code (textual) into Abstract Syntax Tree, and highlight code from AST, rather than current highlight_observer.

noticeable APIs:

  • attach_highlight
  • highlight_observer
  • observer_rep::set_highlight
  • language
    • language::has_highlight
    • language::highlight

Bonus work

  • Structural navigation of cursor, consistent with other parts.
  • Edit code can make change to AST, such as semantic insertion and deletion.
  • Format code according to AST.
  • Highlight or edit code from other APIs.

Works not included

  • Highlight or edit code from LSP mentioned by @Oyyko. Because LSP may take effect on a whole project or a bunch of files, but such structure is not included in Mogan, thus LSP is overkilled for current highlighting usage.

See also

1 Like

Maybe we can use LSP protocal.
see https://www.reddit.com/r/neovim/comments/1109wgr/treesitter_vs_lsp_differences_ans_overlap/

Integration with tree-sitter is too big for a project. It is fine in a proposal.

If you start to make this proposal as a project, you should make it feasible for a student to complete within 3 months. I think for an OSPP project, syntax highlighting via tree-sitter is good enough, complicated enough and hard enough.

First of all, we should improve the current syntax highlight implementation.