From 40b6359f22dee9a9a58cb3decfa807647bccab90 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 30 Aug 2026 10:02:28 +0200 Subject: [PATCH] Added isLanguageSpecific to scope references --- .../src/references/scopeReferences.ts | 79 ++++++++++++++++- .../src/scopeProviders/ScopeInfoProvider.ts | 87 +------------------ 2 files changed, 77 insertions(+), 89 deletions(-) diff --git a/packages/lib-common/src/references/scopeReferences.ts b/packages/lib-common/src/references/scopeReferences.ts index b545a80337f..da4848dac54 100644 --- a/packages/lib-common/src/references/scopeReferences.ts +++ b/packages/lib-common/src/references/scopeReferences.ts @@ -20,6 +20,11 @@ import { connectiveDefaultSpokenForms } from "./spokenForms/connectiveDefaultSpo import { graphemeDefaultSpokenForms } from "./spokenForms/graphemeDefaultSpokenForms"; import { ordinalDefaultSpokenForms } from "./spokenForms/numberDefaultSpokenForms"; +interface ScopeReferenceEntry extends ReferenceEntry { + /** Whether the scope is defined on a per-language basis. */ + isLanguageSpecific: boolean; +} + const DEFAULT_PATTERN = VAR_SPOKEN_FORM; const AIR = graphemeDefaultSpokenForms.a; @@ -34,6 +39,7 @@ const FOURTH = ordinalDefaultSpokenForms[4]; export const scopeReferences = { // Group: text character: { + isLanguageSpecific: false, name: "Character", group: { id: "text", index: 0 }, defaultSpokenForm: "char", @@ -52,6 +58,7 @@ export const scopeReferences = { ], }, word: { + isLanguageSpecific: false, name: "Sub token word", group: { id: "text", index: 1 }, defaultSpokenForm: "sub", @@ -78,6 +85,7 @@ export const scopeReferences = { ], }, token: { + isLanguageSpecific: false, name: "Token", group: { id: "text", index: 2 }, defaultSpokenForm: "token", @@ -98,6 +106,7 @@ export const scopeReferences = { ], }, identifier: { + isLanguageSpecific: false, name: "Identifier", group: { id: "text", index: 3 }, defaultSpokenForm: "identifier", @@ -118,6 +127,7 @@ export const scopeReferences = { ], }, sentence: { + isLanguageSpecific: false, name: "Sentence", group: { id: "text", index: 4 }, defaultSpokenForm: "sentence", @@ -137,6 +147,7 @@ export const scopeReferences = { ], }, line: { + isLanguageSpecific: false, name: "Line", group: { id: "text", index: 5 }, defaultSpokenForm: LINE, @@ -155,6 +166,7 @@ export const scopeReferences = { ], }, fullLine: { + isLanguageSpecific: false, name: "Full line", group: { id: "text", index: 6 }, defaultSpokenForm: "full line", @@ -173,6 +185,7 @@ export const scopeReferences = { ], }, paragraph: { + isLanguageSpecific: false, name: "Paragraph", group: { id: "text", index: 7 }, defaultSpokenForm: "block", @@ -193,6 +206,7 @@ export const scopeReferences = { ], }, boundedParagraph: { + isLanguageSpecific: false, name: "Bounded paragraph", group: { id: "text", index: 8 }, defaultSpokenForm: "short block", @@ -213,6 +227,7 @@ export const scopeReferences = { ], }, document: { + isLanguageSpecific: false, name: "Document", group: { id: "text", index: 9 }, defaultSpokenForm: "file", @@ -232,6 +247,7 @@ export const scopeReferences = { ], }, nonWhitespaceSequence: { + isLanguageSpecific: false, name: "Non-whitespace sequence", group: { id: "text", index: 10 }, defaultSpokenForm: "paint", @@ -252,6 +268,7 @@ export const scopeReferences = { ], }, boundedNonWhitespaceSequence: { + isLanguageSpecific: false, name: "Bounded non-whitespace sequence", group: { id: "text", index: 11 }, defaultSpokenForm: "short paint", @@ -274,6 +291,7 @@ export const scopeReferences = { ], }, url: { + isLanguageSpecific: false, name: "URL", group: { id: "text", index: 12 }, defaultSpokenForm: "link", @@ -292,6 +310,7 @@ export const scopeReferences = { ], }, surroundingPair: { + isLanguageSpecific: false, name: "Surrounding pair", group: { id: "text", index: 13 }, description: `Expands the input to the nearest containing [paired delimiters](../paired-delimiters.md) and their contents. Use the [interior-only](../modifiers/interiorOnly.mdx) or [exclude-interior](../modifiers/excludeInterior.mdx) modifiers to select only the contents or only the delimiters. @@ -312,6 +331,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, glyph: { + isLanguageSpecific: false, name: "Glyph", group: { id: "text", index: 14 }, defaultSpokenForm: "glyph", @@ -332,6 +352,7 @@ When an opening and closing delimiter use the same character and no parse-tree i // Group: documentHierarchy part: { + isLanguageSpecific: true, name: "Part", group: { id: "documentHierarchy", index: 0 }, defaultSpokenForm: "part", @@ -350,6 +371,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, chapter: { + isLanguageSpecific: true, name: "Chapter", group: { id: "documentHierarchy", index: 1 }, defaultSpokenForm: "chapter", @@ -368,6 +390,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, subSection: { + isLanguageSpecific: true, name: "Subsection", group: { id: "documentHierarchy", index: 2 }, defaultSpokenForm: "subsection", @@ -386,6 +409,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, subSubSection: { + isLanguageSpecific: true, name: "Subsubsection", group: { id: "documentHierarchy", index: 3 }, defaultSpokenForm: "subsubsection", @@ -404,6 +428,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, namedParagraph: { + isLanguageSpecific: true, name: "Named paragraph", group: { id: "documentHierarchy", index: 4 }, defaultSpokenForm: "paragraph", @@ -422,6 +447,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, subParagraph: { + isLanguageSpecific: true, name: "Subparagraph", group: { id: "documentHierarchy", index: 5 }, defaultSpokenForm: "subparagraph", @@ -440,6 +466,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, environment: { + isLanguageSpecific: true, name: "Environment", group: { id: "documentHierarchy", index: 6 }, defaultSpokenForm: "environment", @@ -460,6 +487,7 @@ When an opening and closing delimiter use the same character and no parse-tree i // Group: collections list: { + isLanguageSpecific: true, name: "List", group: { id: "collections", index: 0 }, defaultSpokenForm: "list", @@ -478,6 +506,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, map: { + isLanguageSpecific: true, name: "Map", group: { id: "collections", index: 1 }, defaultSpokenForm: "map", @@ -496,6 +525,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, collectionItem: { + isLanguageSpecific: true, name: "Collection item", group: { id: "collections", index: 2 }, defaultSpokenForm: ITEM, @@ -514,6 +544,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, collectionKey: { + isLanguageSpecific: true, name: "Collection key", group: { id: "collections", index: 3 }, defaultSpokenForm: "key", @@ -534,6 +565,7 @@ When an opening and closing delimiter use the same character and no parse-tree i // Group: functions argumentOrParameter: { + isLanguageSpecific: true, name: "Argument or parameter", group: { id: "functions", index: 0 }, defaultSpokenForm: "arg", @@ -552,6 +584,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, argumentList: { + isLanguageSpecific: true, name: "Argument list", group: { id: "functions", index: 1 }, defaultSpokenForm: "arg list", @@ -570,6 +603,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, anonymousFunction: { + isLanguageSpecific: true, name: "Anonymous function", group: { id: "functions", index: 2 }, defaultSpokenForm: "lambda", @@ -588,6 +622,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, namedFunction: { + isLanguageSpecific: true, name: "Named function", group: { id: "functions", index: 3 }, defaultSpokenForm: "funk", @@ -606,6 +641,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, functionName: { + isLanguageSpecific: true, name: "Function name", group: { id: "functions", index: 4 }, defaultSpokenForm: "funk name", @@ -624,6 +660,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, functionCall: { + isLanguageSpecific: true, name: "Function call", group: { id: "functions", index: 5 }, defaultSpokenForm: "call", @@ -642,6 +679,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, functionCallee: { + isLanguageSpecific: true, name: "Function callee", group: { id: "functions", index: 6 }, defaultSpokenForm: "callee", @@ -662,6 +700,7 @@ When an opening and closing delimiter use the same character and no parse-tree i // Group: objects class: { + isLanguageSpecific: true, name: "Class", group: { id: "objects", index: 0 }, defaultSpokenForm: "class", @@ -680,6 +719,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, className: { + isLanguageSpecific: true, name: "Class name", group: { id: "objects", index: 1 }, defaultSpokenForm: "class name", @@ -698,6 +738,7 @@ When an opening and closing delimiter use the same character and no parse-tree i ], }, instance: { + isLanguageSpecific: true, name: "Instance", group: { id: "objects", index: 2 }, defaultSpokenForm: "instance", @@ -731,6 +772,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, name: { + isLanguageSpecific: true, name: "Name", group: { id: "objects", index: 3 }, defaultSpokenForm: "name", @@ -750,6 +792,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, attribute: { + isLanguageSpecific: true, name: "Attribute", group: { id: "objects", index: 4 }, defaultSpokenForm: "attribute", @@ -768,6 +811,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, type: { + isLanguageSpecific: true, name: "Type", group: { id: "objects", index: 5 }, defaultSpokenForm: "type", @@ -786,6 +830,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, value: { + isLanguageSpecific: true, name: "Value", group: { id: "objects", index: 6 }, defaultSpokenForm: "value", @@ -807,6 +852,7 @@ For a range target, the entire range becomes the search text. Without an explici // Group: statements statement: { + isLanguageSpecific: true, name: "Statement", group: { id: "statements", index: 0 }, defaultSpokenForm: STATEMENT, @@ -826,6 +872,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, branch: { + isLanguageSpecific: true, name: "Branch", group: { id: "statements", index: 1 }, defaultSpokenForm: "branch", @@ -845,6 +892,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, ifStatement: { + isLanguageSpecific: true, name: "If statement", group: { id: "statements", index: 2 }, defaultSpokenForm: "if state", @@ -863,6 +911,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, condition: { + isLanguageSpecific: true, name: "Condition", group: { id: "statements", index: 3 }, defaultSpokenForm: "condition", @@ -881,6 +930,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, comment: { + isLanguageSpecific: true, name: "Comment", group: { id: "statements", index: 4 }, defaultSpokenForm: "comment", @@ -899,6 +949,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, command: { + isLanguageSpecific: true, name: "Command", group: { id: "statements", index: 5 }, defaultSpokenForm: "command", @@ -918,6 +969,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, regularExpression: { + isLanguageSpecific: true, name: "Regular expression", group: { id: "statements", index: 6 }, defaultSpokenForm: "regex", @@ -938,6 +990,7 @@ For a range target, the entire range becomes the search text. Without an explici // Group: markup xmlElement: { + isLanguageSpecific: true, name: "XML element", group: { id: "markup", index: 0 }, defaultSpokenForm: "element", @@ -957,6 +1010,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, xmlStartTag: { + isLanguageSpecific: true, name: "XML start tag", group: { id: "markup", index: 1 }, defaultSpokenForm: "start tag", @@ -975,6 +1029,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, xmlEndTag: { + isLanguageSpecific: true, name: "XML end tag", group: { id: "markup", index: 2 }, defaultSpokenForm: "end tag", @@ -993,6 +1048,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, xmlBothTags: { + isLanguageSpecific: true, name: "XML both tags", group: { id: "markup", index: 3 }, defaultSpokenForm: "tags", @@ -1012,6 +1068,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, selector: { + isLanguageSpecific: true, name: "Selector", group: { id: "markup", index: 4 }, defaultSpokenForm: "selector", @@ -1030,6 +1087,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, unit: { + isLanguageSpecific: true, name: "Unit", group: { id: "markup", index: 5 }, defaultSpokenForm: "unit", @@ -1050,6 +1108,7 @@ For a range target, the entire range becomes the search text. Without an explici // Group: sections section: { + isLanguageSpecific: true, name: "Section", group: { id: "sections", index: 0 }, defaultSpokenForm: "section", @@ -1069,6 +1128,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelOne: { + isLanguageSpecific: true, name: "Section level one", group: { id: "sections", index: 1 }, defaultSpokenForm: "one section", @@ -1088,6 +1148,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelTwo: { + isLanguageSpecific: true, name: "Section level two", group: { id: "sections", index: 2 }, defaultSpokenForm: "two section", @@ -1107,6 +1168,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelThree: { + isLanguageSpecific: true, name: "Section level three", group: { id: "sections", index: 3 }, defaultSpokenForm: "three section", @@ -1126,6 +1188,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelFour: { + isLanguageSpecific: true, name: "Section level four", group: { id: "sections", index: 4 }, defaultSpokenForm: "four section", @@ -1145,6 +1208,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelFive: { + isLanguageSpecific: true, name: "Section level five", group: { id: "sections", index: 5 }, defaultSpokenForm: "five section", @@ -1164,6 +1228,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, sectionLevelSix: { + isLanguageSpecific: true, name: "Section level six", group: { id: "sections", index: 6 }, defaultSpokenForm: "six section", @@ -1185,6 +1250,7 @@ For a range target, the entire range becomes the search text. Without an explici // Group: notebook notebookCell: { + isLanguageSpecific: false, name: "Notebook cell", group: { id: "notebook", index: 0 }, defaultSpokenForm: "cell", @@ -1205,6 +1271,7 @@ For a range target, the entire range becomes the search text. Without an explici // Group: private "private.fieldAccess": { + isLanguageSpecific: true, name: "Field access", group: { id: "private", index: 0 }, defaultSpokenForm: "access", @@ -1224,6 +1291,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, string: { + isLanguageSpecific: true, name: "String", group: { id: "private", index: 1 }, defaultSpokenForm: "parse tree string", @@ -1243,6 +1311,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, textFragment: { + isLanguageSpecific: true, name: "Text fragment", group: { id: "private", index: 2 }, defaultSpokenForm: "text fragment", @@ -1262,6 +1331,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, disqualifyDelimiter: { + isLanguageSpecific: true, name: "Disqualify delimiter", group: { id: "private", index: 3 }, defaultSpokenForm: "disqualify delimiter", @@ -1281,6 +1351,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, pairDelimiter: { + isLanguageSpecific: true, name: "Pair delimiter", group: { id: "private", index: 4 }, defaultSpokenForm: "pair delimiter", @@ -1300,6 +1371,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, interior: { + isLanguageSpecific: true, name: "Interior", group: { id: "private", index: 5 }, defaultSpokenForm: "interior", @@ -1319,6 +1391,7 @@ For a range target, the entire range becomes the search text. Without an explici ], }, surroundingPairInterior: { + isLanguageSpecific: false, name: "Surrounding pair interior", group: { id: "private", index: 6 }, private: true, @@ -1326,13 +1399,11 @@ For a range target, the entire range becomes the search text. Without an explici examples: [], }, customRegex: { + isLanguageSpecific: false, name: "Custom regex", group: { id: "private", index: 7 }, private: true, syntaxes: [], examples: [], }, -} as const satisfies Record< - ScopeTypeType, - ReferenceEntry ->; +} as const satisfies Record; diff --git a/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts b/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts index 55709e15cab..74c309d162a 100644 --- a/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts +++ b/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts @@ -8,6 +8,7 @@ import type { } from "@cursorless/lib-common"; import { isPseudoScopeType, + scopeReferences, simpleScopeTypeTypes, surroundingPairNames, } from "@cursorless/lib-common"; @@ -97,7 +98,7 @@ export class ScopeInfoProvider { spokenForm: this.customSpokenFormGenerator.scopeTypeToSpokenForm(scopeType), humanReadableName: scopeTypeToString(scopeType), - isLanguageSpecific: isLanguageSpecific(scopeType), + isLanguageSpecific: scopeReferences[scopeType.type].isLanguageSpecific, }; } @@ -105,87 +106,3 @@ export class ScopeInfoProvider { this.disposable.dispose(); } } - -/** - * @param scopeType The scope type to check - * @returns A boolean indicating whether the given scope type is defined on a - * per-language basis. - */ -function isLanguageSpecific(scopeType: ScopeType): boolean { - switch (scopeType.type) { - case "string": - case "argumentOrParameter": - case "argumentList": - case "anonymousFunction": - case "attribute": - case "branch": - case "class": - case "className": - case "collectionItem": - case "collectionKey": - case "command": - case "comment": - case "private.fieldAccess": - case "functionCall": - case "functionCallee": - case "functionName": - case "ifStatement": - case "instance": - case "interior": - case "list": - case "map": - case "name": - case "namedFunction": - case "regularExpression": - case "statement": - case "type": - case "value": - case "condition": - case "section": - case "sectionLevelOne": - case "sectionLevelTwo": - case "sectionLevelThree": - case "sectionLevelFour": - case "sectionLevelFive": - case "sectionLevelSix": - case "selector": - case "unit": - case "xmlBothTags": - case "xmlElement": - case "xmlEndTag": - case "xmlStartTag": - case "part": - case "chapter": - case "subSection": - case "subSubSection": - case "namedParagraph": - case "subParagraph": - case "environment": - case "textFragment": - case "disqualifyDelimiter": - case "pairDelimiter": - return true; - - case "character": - case "word": - case "token": - case "identifier": - case "line": - case "fullLine": - case "sentence": - case "paragraph": - case "boundedParagraph": - case "document": - case "nonWhitespaceSequence": - case "boundedNonWhitespaceSequence": - case "url": - case "notebookCell": - case "surroundingPair": - case "surroundingPairInterior": - case "customRegex": - case "glyph": - return false; - - // No default - } -}