cursorless
cursorless copied to clipboard
Initial work for scopeType matchers based on Tree-Sitter's Query DSL
Partially addresses #616
I'm considering renaming this branch since it has moved away from a "scheme-scope-demo" and now implements some scopeType matchers for Ruby.
Todo:
- Extract scopeTypes to constants file. Although, is this necessary with @AndreasArvidsson's recent work?
- Add unit test for generation of matchers
Remaining Questions:
- Currently extension path is stored on
this.graph, what is the best way to get this down into thenodeMatchercode so we can use it to load queries? - For range expanding matches which return more than one node, which node should be returned from the matcher? Is this even a concept we want to support?
- Expanding
NodeMatcherValueto take either aTreeorSyntaxNodefelt like a kludge to me. I'm thinking creating a new v1 interface for this and rolling back the union type, thoughts?
Fixes https://github.com/cursorless-dev/cursorless/issues/436
- [ ] Close https://github.com/cursorless-dev/cursorless/issues/785 if we fix that
- [ ] Comment on #484 saying the process has started and providing link to example
- [ ] Close https://github.com/cursorless-dev/cursorless/issues/797 if we fix that
Shouldn't we use https://github.com/nvim-treesitter/tree-sitter-query instead of scheme?
Also worth mentioning https://marketplace.visualstudio.com/items?itemName=jrieken.vscode-tree-sitter-query, which defines a language id for tree sitter queries
sg!
As discussed in meet-up, algorithm is as follows:
- Split range into start and end position
- For the start position
- Find smallest
domainthat contains or is adjacent to position - If there are two such nodes, pick the one to the right
- Find smallest
- If the end position is contained or adjacent to the
domainreturned in previous step, return the tagged range - Otherwise, run steps 2.1 and 2.2 on the end node
- If the start position is contained or adjacent to
domainreturned in previous step, return the tagged range - Otherwise, return the range from the start tagged range to the end tagged range, with direction taken from selection
I am currently getting compile errors on the head of that branch:
$ tsc -p ./
src/processTargets/modifiers/scopeTypeStages/ContainingSyntaxScopeStage.ts:23:1 - error TS1128: Declaration or statement expected.
23 } from "../../../typings/targetDescriptor.types";
~
src/processTargets/modifiers/scopeTypeStages/ContainingSyntaxScopeStage.ts:23:3 - error TS1434: Unexpected keyword or identifier.
23 } from "../../../typings/targetDescriptor.types";
~~~~
Found 2 errors in the same file, starting at: src/processTargets/modifiers/scopeTypeStages/ContainingSyntaxScopeStage.ts:23
PR to fix the issues in HEAD: https://github.com/Will-Sommers/cursorless-vscode/pull/2
@Will-Sommers What is the rationale behind defining all scope types in a single query?
@Will-Sommers What is the rationale behind defining all scope types in a single query?
good question. Having one big query seems to be the convention that other repos are using; see the links in the description of #616. I could see performance being superior if we split it up, but it is easier to have one file per language, esp since most queries are fairly small
Ok this one is good to go, but unfortunately it breaks "every funk" for Ruby. I created https://github.com/cursorless-dev/cursorless/pull/1430 to fix that issue. That PR is ready, so would be great if you could have a look when you get a minute. I think they should prob merge in together so we don't break "every funk" in Ruby on main