cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Initial work for scopeType matchers based on Tree-Sitter's Query DSL

Open Will-Sommers opened this issue 3 years ago • 8 comments

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 the nodeMatcher code 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 NodeMatcherValue to take either a Tree or SyntaxNode felt 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

Will-Sommers avatar Apr 08 '22 16:04 Will-Sommers

Shouldn't we use https://github.com/nvim-treesitter/tree-sitter-query instead of scheme?

pokey avatar Apr 08 '22 18:04 pokey

Also worth mentioning https://marketplace.visualstudio.com/items?itemName=jrieken.vscode-tree-sitter-query, which defines a language id for tree sitter queries

pokey avatar Apr 08 '22 18:04 pokey

sg!

Will-Sommers avatar Apr 15 '22 01:04 Will-Sommers

As discussed in meet-up, algorithm is as follows:

  1. Split range into start and end position
  2. For the start position
    1. Find smallest domain that contains or is adjacent to position
    2. If there are two such nodes, pick the one to the right
  3. If the end position is contained or adjacent to the domain returned in previous step, return the tagged range
  4. Otherwise, run steps 2.1 and 2.2 on the end node
  5. If the start position is contained or adjacent to domain returned in previous step, return the tagged range
  6. Otherwise, return the range from the start tagged range to the end tagged range, with direction taken from selection

pokey avatar May 24 '22 15:05 pokey

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

wenkokke avatar Jun 13 '22 12:06 wenkokke

PR to fix the issues in HEAD: https://github.com/Will-Sommers/cursorless-vscode/pull/2

wenkokke avatar Jun 13 '22 13:06 wenkokke

@Will-Sommers What is the rationale behind defining all scope types in a single query?

wenkokke avatar Jun 13 '22 13:06 wenkokke

@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

pokey avatar Jun 13 '22 13:06 pokey

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

pokey avatar Apr 18 '23 19:04 pokey