Repository navigation
Replies: 16 comments 7 replies
|
I ultimately decided against trying to use tree-sitter. Some compiled language grammars are 1+MB in size, whereas all 100+ language lexers Textadept currently contains are about 500KB combined. Tree-sitter is extremely inefficient size-wise and would bloat Textadept considerably. I did not know this at the time of the announcement. |
|
Yes, but most people don’t use 100+ languages, only a few, may be four or five at most. And there is no need to bundle any with Textadept, just to have a documentation explaining how to install one. Then people could be free to install some or none. This is like with language servers, some are surprisingly big in size, but it’s not required to install any. But if tree-sitter is not easy to integrate, this may be another issue (I don’t know) |
|
Looking at the lexers directory, it appears it has changed a lot since Textadept 10. Now it is Lua Lua LPeg lexers. Found this page about it: https://scintilla.sourceforge.io/LPegLexer.html . There is also something called Scintillua in Textadept, which I have not read about yet: https://orbitalquark.github.io/scintillua/ Is this the only API for colorization or is there another one? This is just to know if there could be a way to interface an API already existing in Textadept, with the API of Tree-sitter, which I have not studied yet, I just know the principles which I like (and what I like too, is that it is a kind of standard and also goes beyond the lexical level). Will read these documentations first, later. |
|
Thanks, will surely have a look at this a future day :) |
|
Why STYLE_DEFAULT? Shouldn’t this be something returned the lexer? |
|
As an example, this STYLE_KEYWORD. When some text range should be styled with STYLE_KEYWORD, how is this set? With a buffer with some text as the first line, I tried this at the Lua prompt (Ctrl+E), but it did nothing: buffer:start_styling(0, 0); buffer:set_styling(10, view.STYLE_KEYWORD) Then I wanted to look into “core/buffer.lua” for Probably I should look at Sinctillua first. @rgieseke also looking at the link you suggested |
|
I had just missed the line Here is what I could understand. As said in the documentation, If there is a second event handler attached for The range starts at
There is a styles = buffer.lexer:lex(buffer:text_range(start_pos, end_pos), init_style)where The It should be enough for a start, except for the |
|
Just wanted to be sure, so checked it again. Indeed, |
|
There is a Lua binding for tree-sitter libraries: https://github.com/euclidianAce/ltreesitter . It has to be installed with Luarocks. Once installed, it appears to be a shared library. It can be installed in Textadept’s Lua by copying/symlinking the file in the user config If a Tree-sitter library is installed somewhere, a symlink can be made to it, from a location indicated in Checked the binding provided by LTreesitter, works. With Tree-sitter, there is a matter of ABI version. It seems the tree-sitter library version, like in Tree-sitter libraries must not be confused with the LTreesitter library. The API looks a bit like the HTML DOM, not the same, just for the idea. A look at the API confirms this feeling: https://euclidianace.github.io/ltreesitter/ . The original C happy API is described there: https://tree-sitter.github.io/tree-sitter/using-parsers/index.html There must be something to tell a parser some range of text was changed. Have not yet looked at that. For simple things which does not require type inference or resolution, name resolution, or inter module dependencies, Tree-sitter will be lighter than a language server. Ex. to list the global definitions in a file or the local definitions in a function, parsing is enough, so Tree-sitter is. By the way, for this usage, there is no need to change the way Textadept colorize files. This is just that in some case, the colorization will be more exact and precise than the one a regex lexer can give. Nested languages is supported by Tree-sitter. Probably it just needs the library for the nested language to be installed too. On this topic, this may be interesting: https://lambdaland.org/posts/2026-01-21_tree-sitter_vs_lsp/ , commented here: https://news.ycombinator.com/item?id=46719899 |
|
Just so you know, events.connect(events.STYLE_NEEDED, function(end_pos, buffer)
-- 1. Setup data for treesitter like buffer text range.
-- 2. Call treesitter (the library you mentioned needs to be built against Lua 5.5)
-- 3. Call `buffer:start_styling()`
-- 4. Iterate through treesitter output, calling `buffer:set_styling()` for each range.
-- 5. If necessary, call `buffer:set_styling()` up to `end_pos` if treesitter doesn't do so.
return true -- do not let Textadept run its own event handler
end, 1) |
|
Thanks for direction, it will help a lot (for people who read, would just add it has to return nil when it does not handle the event, since I made the error … it's documented). I’m not sure, but wondered if there may be an error in this line: buffer:set_styling(end_pos - start_pos, view.STYLE_DEFAULT)Shouldn’t this be |
|
As a side note, when the end of line mode of a buffer is CR+LF, it is also CR+LF in the buffer data. This is not just for saving and reading files. This is a good thing, because some applications care about CR and the content of a buffer may be sent to an external application. Probably tree-sitter interprets CR as white space, because it has no issue with it. Note taken here, just because this may be interesting for some people. |
|
Edit: this message was mentioning two issues with https://github.com/euclidianAce/ltreesitter but it was me mixing some things. Could have a working colorizer for Python, modulo the first issue, but it does not seem good enough so far. It’s a Lua version, not yet started the version as a C module. Edit: finally there will not be a version as C module, better something else in the future. |
|
May be this is what was to be added in Textadept: https://github.com/orbitalquark/tslexia It is marked as archived since April 2026. |
|
Tree-sitter is not really as perfect as it is sometime advertised. The API is not designed to be a standard API as I expected (will tell more on this a future day) and the grammars are not always OK. If it is to be used to implement a colorizer only, it’s OK, but if it is to go further, there may be issue. (edit: don’t miss the edit at the end of this paragraph) One is inconsistency between grammars. A node has a type and an optional field name. When a node has a field name, it means it is part of the abstract syntax tree, as the documentation says, but it is not as clean. There are things which do not have a name while there are obviously needed in the abstract syntax tree. An example is Python strings, whose string content don’t have a field name, meaning the content is treated as purely syntactical, like the string’s open and close delimiters ; it’s not OK. It’s the opposite with the Lua grammar, which says the string delimiters are part of the abstract tree, just like the string content. This is inconsistency between grammars and also with the documentation. The distinction between abstract syntax and concrete syntax node, is relevant only for leaf nodes, non-leaf nodes can only be abstract. Abstract leaf node are important, because there hold primitive values, identifiers and the likes. This is why I feel disappointed about this distinction not taken seriously. But it can be explained if Tree-sitter is mainly seen as a lexer more than as a parser. Edit: I had some confusion due to some real issues. To learn more and understand the how and why, see this discussion, and not only the selected answer, also some other comments I added: euclidianAce/ltreesitter#47 There are also issue like the Python grammar not taking care of indents, while Python syntax rely a lot on indent and it is even famous for that. Another example issue is with HTML. An attribute with a value has a I have a reason to next expect these kind of errors to be ever fixed, otherwise, I would mention these as bugs is the relevant repositories, not here. Unless there are independent and no authoritarian people took-over it, and there are a few, at least: reStructuredText (maintained by stsewd), SML (maintained by MatthewFluet), SQL (maintained by DerekStride), SQLite (by dhcmrlchtdj, archived, not maintained anymore) and TOML (maintained by ikatyang), all independant. The tree-sitter repository may be less worse (unless otherwise witnessed, not so fat) than tree-sitter-grammars (alias, “take-over everything I can”), but even the tree-sitter repository is hardly opened to communication, unlike with independent, like euclidianAce, the author of the Lua binding I use. It may still be nice, half-way between a simple colorizer and access to some meaning like with language server, while more limited but also more lightweight. |
|
Styling is different. Mapping a node type to a style tag gives good result, but people may be disappointed with some result. An example with Lua: function f()
end
f()With the Textadept’s lexer, there is a function style tag. But it is applied to the function keyword, not to the name in the function call at the end. The parsed tree help to understand: The “f” in the function call is an identifier. To colorize it as it like people may expect it to be when they are used to Textadept’s lexer, would require to take the context into account, that is, to colorize the Instead of a simple mapping, it would require rules looking like Is it important or not? Or would a simple node types mapping to style tags, be enough? The idea to take the context into account, would still be nice. It seems GitHub takes context into account (it uses Tree-sitter to colorize source sample in comments). Something else also looking differently, is with strings and comments. Most lexers colorize the whole with a single style. With Tree-sitter (rather the grammars for it), a distinction is always made between the content and the delimiters. I remember I did something similar a long time ago for an Ada lexer and was not sure if it was looking fine or not. If it’s not too much disturbing, it may be finally better, because delimiters are not par of the content. Can you imagine "Abc" with Abc colorized as a string and the enclosing quotes colorized as a punctuation? That said, it is possible to map the type of quotes to the style tag of string, to have it colorized as most people are used to. The same with the Lua function keyword, which can be mapped to keyword ; it is just it’s type, function, which makes it mapped to the function style by default, while it is not fixed. Mappings are to be user defined, there is just an automatic default which is often a reasonable minimum, except with HTML (and may be others I have not noticed). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The page #362 was announcing Textadept will support tree-sitter for syntax highlighting (and some people use tree-sitter for other syntax related things). But the manual, https://github.com/orbitalquark/textadept/blob/default/docs/manual.md , does not mention it and searching in the discussions, I could find nothing, except a quick mention of it and the discussion announcing it.
I feel to guess it is still there, since it was announced.
Please, do someone know some documents to read, about it?
All reactions