Skip to content

Commit 2f15dc6

Browse files
Only do contiguous for comments
1 parent fe7e8e5 commit 2f15dc6

File tree

20 files changed

+58
-278
lines changed

20 files changed

+58
-278
lines changed
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
from talon import Module
42

53
mod = Module()
@@ -14,45 +12,42 @@
1412
"cursorless_custom_regex_scope_type_plural",
1513
desc="Supported plural custom regular expression scope types",
1614
)
17-
mod.list(
18-
"cursorless_contiguous_scope_type",
19-
desc="Cursorless contiguous scope type",
20-
)
2115

2216

2317
@mod.capture(
24-
rule="[{user.cursorless_contiguous_scope_type}] ({user.cursorless_scope_type} | {user.cursorless_custom_regex_scope_type})"
18+
rule="{user.cursorless_scope_type} | <user.cursorless_glyph_scope_type> | {user.cursorless_custom_regex_scope_type}"
2519
)
26-
def cursorless_scope_type(m) -> dict[str, Any]:
20+
def cursorless_scope_type(m) -> dict[str, str]:
2721
"""Cursorless scope type singular"""
2822
try:
29-
scope_type = {"type": m.cursorless_scope_type}
23+
return {"type": m.cursorless_scope_type}
3024
except AttributeError:
31-
scope_type = {
32-
"type": "customRegex",
33-
"regex": m.cursorless_custom_regex_scope_type,
34-
}
25+
pass
3526

3627
try:
37-
return {"type": m.cursorless_contiguous_scope_type, "scopeType": scope_type}
28+
return m.cursorless_glyph_scope_type
3829
except AttributeError:
39-
return scope_type
30+
pass
31+
32+
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
4033

4134

4235
@mod.capture(
43-
rule="[{user.cursorless_contiguous_scope_type}] ({user.cursorless_scope_type_plural} | {user.cursorless_custom_regex_scope_type_plural})"
36+
rule="{user.cursorless_scope_type_plural} | <user.cursorless_glyph_scope_type_plural> | {user.cursorless_custom_regex_scope_type_plural}"
4437
)
45-
def cursorless_scope_type_plural(m) -> dict[str, Any]:
38+
def cursorless_scope_type_plural(m) -> dict[str, str]:
4639
"""Cursorless scope type plural"""
4740
try:
48-
scope_type = {"type": m.cursorless_scope_type_plural}
41+
return {"type": m.cursorless_scope_type_plural}
4942
except AttributeError:
50-
scope_type = {
51-
"type": "customRegex",
52-
"regex": m.cursorless_custom_regex_scope_type_plural,
53-
}
43+
pass
5444

5545
try:
56-
return {"type": m.cursorless_contiguous_scope_type, "scopeType": scope_type}
46+
return m.cursorless_glyph_scope_type_plural
5747
except AttributeError:
58-
return scope_type
48+
pass
49+
50+
return {
51+
"type": "customRegex",
52+
"regex": m.cursorless_custom_regex_scope_type_plural,
53+
}

cursorless-talon/src/spoken_forms.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"visible": "visible"
8282
},
8383
"simple_scope_modifier": { "every": "every" },
84-
"contiguous_scope_type": { "fat": "contiguous" },
8584
"interior_modifier": {
8685
"inside": "interiorOnly"
8786
},

packages/common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,11 @@ export interface OneOfScopeType {
205205
scopeTypes: ScopeType[];
206206
}
207207

208-
export interface ContiguousScopeType {
209-
type: "contiguous";
210-
scopeType: ScopeType;
211-
}
212-
213208
export type ScopeType =
214209
| SimpleScopeType
215210
| SurroundingPairScopeType
216211
| CustomRegexScopeType
217-
| OneOfScopeType
218-
| ContiguousScopeType;
212+
| OneOfScopeType;
219213

220214
export interface ContainingSurroundingPairModifier
221215
extends ContainingScopeModifier {

packages/cursorless-engine/src/generateSpokenForm/primitiveTargetToSpokenForm.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,6 @@ export class PrimitiveTargetSpokenFormGenerator {
209209
case "oneOf":
210210
throw new NoSpokenFormError(`Scope type '${scopeType.type}'`);
211211

212-
case "contiguous": {
213-
const scope = this.handleScopeType(scopeType.scopeType);
214-
return [this.spokenFormMap.modifierExtra.contiguousScope, scope];
215-
}
216-
217212
case "surroundingPair": {
218213
const pair = this.spokenFormMap.pairedDelimiter[scopeType.delimiter];
219214
if (scopeType.forceDirection != null) {

packages/cursorless-engine/src/languages/LanguageDefinition.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { ScopeType, SimpleScopeType, showError } from "@cursorless/common";
22
import { existsSync, readFileSync } from "fs";
33
import { dirname, join } from "path";
44
import { TreeSitterScopeHandler } from "../processTargets/modifiers/scopeHandlers";
5+
import { ContiguousScopeHandler } from "../processTargets/modifiers/scopeHandlers/ContiguousScopeHandler";
56
import { TreeSitterTextFragmentScopeHandler } from "../processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/TreeSitterTextFragmentScopeHandler";
6-
import { ScopeHandler } from "../processTargets/modifiers/scopeHandlers/scopeHandler.types";
7+
import type { ScopeHandler } from "../processTargets/modifiers/scopeHandlers/scopeHandler.types";
78
import { ide } from "../singletons/ide.singleton";
8-
import { TreeSitter } from "../typings/TreeSitter";
9+
import type { TreeSitter } from "../typings/TreeSitter";
910
import { matchAll } from "../util/regex";
1011
import { TreeSitterQuery } from "./TreeSitterQuery";
1112
import { TEXT_FRAGMENT_CAPTURE_NAME } from "./captureNames";
@@ -60,12 +61,21 @@ export class LanguageDefinition {
6061
* undefined if the given scope type / language id combination is still using
6162
* legacy pathways
6263
*/
63-
getScopeHandler(scopeType: ScopeType) {
64+
getScopeHandler(scopeType: ScopeType): ScopeHandler | undefined {
6465
if (!this.query.captureNames.includes(scopeType.type)) {
6566
return undefined;
6667
}
6768

68-
return new TreeSitterScopeHandler(this.query, scopeType as SimpleScopeType);
69+
const scopeHandler = new TreeSitterScopeHandler(
70+
this.query,
71+
scopeType as SimpleScopeType,
72+
);
73+
74+
if (scopeType.type === "comment") {
75+
return new ContiguousScopeHandler(scopeHandler);
76+
}
77+
78+
return scopeHandler;
6979
}
7080

7181
getTextFragmentScopeHandler(): ScopeHandler | undefined {

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/ContiguousScopeHandler.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {
2-
ContiguousScopeType,
32
Direction,
43
Position,
54
Range,
65
ScopeType,
76
TextEditor,
87
next,
98
} from "@cursorless/common";
10-
import { ScopeHandlerFactory } from ".";
119
import { Target } from "../../../typings/target.types";
1210
import { constructScopeRangeTarget } from "../constructScopeRangeTarget";
1311
import { BaseScopeHandler } from "./BaseScopeHandler";
@@ -20,21 +18,13 @@ import type {
2018

2119
export class ContiguousScopeHandler extends BaseScopeHandler {
2220
protected readonly isHierarchical = false;
23-
private readonly scopeHandler: ScopeHandler;
2421

25-
constructor(
26-
private scopeHandlerFactory: ScopeHandlerFactory,
27-
public scopeType: ContiguousScopeType,
28-
languageId: string,
29-
) {
22+
constructor(private scopeHandler: ScopeHandler) {
3023
super();
31-
const handler = scopeHandlerFactory.create(scopeType.scopeType, languageId);
32-
if (handler == null) {
33-
throw new Error(
34-
`No available scope handler for '${scopeType.scopeType.type}'`,
35-
);
36-
}
37-
this.scopeHandler = handler;
24+
}
25+
26+
get scopeType(): ScopeType | undefined {
27+
return this.scopeHandler.scopeType;
3828
}
3929

4030
get iterationScopeType(): ScopeType | CustomScopeType {

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
7575
return new CustomRegexScopeHandler(this, scopeType, languageId);
7676
case "custom":
7777
return scopeType.scopeHandler;
78-
case "contiguous":
79-
return new ContiguousScopeHandler(this, scopeType, languageId);
8078
case "instance":
8179
// Handle instance pseudoscope with its own special modifier
8280
throw Error("Unexpected scope type 'instance'");

packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ function isLanguageSpecific(scopeType: ScopeType): boolean {
175175
case "customRegex":
176176
return false;
177177

178-
case "contiguous":
179-
return isLanguageSpecific(scopeType.scopeType);
180-
181178
case "oneOf":
182179
throw Error(
183180
`Can't decide whether scope type ${JSON.stringify(

packages/cursorless-engine/src/spokenForms/SpokenFormType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type ModifierExtra =
5959
| "previous"
6060
| "next"
6161
| "forward"
62-
| "backward"
63-
| "contiguousScope";
62+
| "backward";
6463

6564
export type SpokenFormType = keyof SpokenFormMapKeyTypes;

packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
130130
next: "next",
131131
forward: "forward",
132132
backward: "backward",
133-
contiguousScope: "fat",
134133
},
135134

136135
customRegex: {},

0 commit comments

Comments
 (0)