Comments (7)
I duplicated the buffer content a bunch of times and got a 1k line buffer, then tried the code again. It is still pretty fast, took about 0.1 sec. I think we can probably get away with this approach :-) Add an idle-timer, while-no-input
and double-buffering, and it should be smooth.
from emacs.
I will investigate if your code is faster than the dynamic module option. I mean, it almost certainly is. However, the example I gave is of course just a simplified version of the actual tree generator which is primarily -- but not only -- designed for echo area navigational aid as you traverse your code. See:
Now this is the hacky version; the original rendered a proper subset of the sparse tree but that of course (with ETS) turned out to have some performance bottlenecks. This simplified version is probably 'good enough' though.
from emacs.
Ah, I see, very interesting feature indeed. I'll wait for you result. If it is still not fast enough, you can describe what you do in more detail, and hopefully we can come up with something in C that can boost the performance for this type use use case.
from emacs.
while I'm excited to see tree-sitter getting integrated into the Emacs core, I'd very much like the default imenu integration to be synchronous (but fast) and not do anything in the background that might lead to ~100ms latency spikes.
I'm currently using a primitive custom imenu definition that uses the tree-sitter dynamic module to gather a simple list of method names; it's not as pretty as the hierarchical structure shown here, so having both to choose from would be the ideal solution IMO, but it's quick (~3 to 5 ms on files in the 1K line ballpark).
Note that I'm not currently trying to extract scopes, and I'm not sure if that can be done within tree-sitter's query mechanism or if one would have to manually traverse the AST starting from matched nodes (assuming that is supported by the API). Would that be a major performance bottleneck?
For completeness, this is the primitive implementation I'm using (hence the sebastian/
prefix, it's part of my private config):
(defmacro sebastian/define-tsc-index-function (fn-name query)
`(defun ,fn-name ()
(unless sebastian/tsc--imenu-query
(setq sebastian/tsc--imenu-query (tsc-make-query tree-sitter-language ,query)))
(tsc--without-restriction
(let* ((matches
(tsc-query-matches
sebastian/tsc--imenu-query
(tsc-root-node tree-sitter-tree) #'tsc--buffer-substring-no-properties)))
(mapcar (lambda (match)
(pcase (cdr match)
(`[(name . ,name) (pars . ,pars)]
(cons
(string-replace
"( " "("
(s-collapse-whitespace
(string-join (list (tsc-node-text name) (tsc-node-text pars)))))
(tsc-node-start-position name)))))
matches)))))
;; for C++ buffers:
(sebastian/define-tsc-index-function
nq-cc-index-function
[(function_declarator
[(operator_name) (field_identifier) (scoped_identifier) (identifier)] @name
(parameter_list) @pars)])
(setq imenu-create-index-function #'nq-cc-index-function)
from emacs.
Yes, if we do provide a default tree-sitter imenu integration, it would be like what you showed here. I don't think imenu support scope anyway.
from emacs.
I mean, imenu
was just an example, of course. It should be blazing fast; indeed, it all should, within the limits of what we can do with Emacs and so forth.
from emacs.
glad to hear that, no reason for me to worry then :)
from emacs.
Related Issues (9)
- Errors in the Info manual HOT 3
- Tree sitter integration is not triggering HOT 20
- Query compilation? HOT 3
- 编译出错:tree-sitter.h: 在函数‘CHECK_TS_PARSER’中: HOT 4
- 文档中存在中文字体时会崩溃... HOT 2
- query cpp member function call for fontifying HOT 4
- error raised when capture name is neither a face nor a function HOT 2
- treesit 高亮设置 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emacs.