1- import type { ScopeSupportFacet } from "@cursorless/common" ;
1+ import type {
2+ ScopeSupportFacet ,
3+ ScopeType ,
4+ TextualScopeSupportFacet ,
5+ } from "@cursorless/common" ;
26import {
37 asyncSafety ,
48 languageScopeSupport ,
9+ scopeSupportFacetInfos ,
510 ScopeSupportFacetLevel ,
611 shouldUpdateFixtures ,
712 textualScopeSupportFacetInfos ,
813} from "@cursorless/common" ;
914import { getScopeTestPathsRecursively } from "@cursorless/node-common" ;
15+ import { getCursorlessApi , openNewEditor } from "@cursorless/vscode-common" ;
1016import { assert } from "chai" ;
1117import { groupBy , uniq } from "lodash-es" ;
18+ import { promises as fsp } from "node:fs" ;
1219import { endToEndTestSetup } from "../endToEndTestSetup" ;
20+ // import {
21+ // serializeIterationScopeFixture,
22+ // serializeScopeFixture,
23+ // } from "./serializeScopeFixture";
1324
1425suite ( "Scope test cases" , async function ( ) {
1526 endToEndTestSetup ( this ) ;
@@ -93,58 +104,54 @@ async function testLanguageSupport(languageId: string, testedFacets: string[]) {
93104 }
94105}
95106
96- // eslint-disable-next-line @typescript-eslint/no-unused-vars
97107async function runTest ( file : string , languageId : string , facetId : string ) {
98- console . log ( file ) ;
99-
100- // try {
101- // const { ide, scopeProvider } = (await getCursorlessApi()).testHelpers!;
102- // const { scopeType, isIteration } = getFacetInfo(languageId, facetId);
103- // const fixture = (await fsp.readFile(file, "utf8"))
104- // .toString()
105- // .replaceAll("\r\n", "\n");
106- // const delimiterIndex = fixture.match(/^---$/m)?.index;
107-
108- // assert.isDefined(
109- // delimiterIndex,
110- // "Can't find delimiter '---' in scope fixture",
111- // );
112-
113- // const code = fixture.slice(0, delimiterIndex! - 1);
114-
115- // await openNewEditor(code, { languageId });
116-
117- // const editor = ide.activeTextEditor!;
118-
119- // const outputFixture = ((): string => {
120- // const config = {
121- // visibleOnly: false,
122- // scopeType,
123- // };
124-
125- // if (isIteration) {
126- // const iterationScopes = scopeProvider.provideIterationScopeRanges(
127- // editor,
128- // {
129- // ...config,
130- // includeNestedTargets: false,
131- // },
132- // );
133- // return serializeIterationScopeFixture(code, iterationScopes);
134- // }
135-
136- // const scopes = scopeProvider.provideScopeRanges(editor, config);
137-
138- // return serializeScopeFixture(facetId, code, scopes);
139- // })();
140-
141- // if (!outputFixture) {
142- // console.log(`No scopes found for ${facetId} in ${languageId}`);
108+ const { ide, scopeProvider } = ( await getCursorlessApi ( ) ) . testHelpers ! ;
109+ const { scopeType, isIteration } = getFacetInfo ( languageId , facetId ) ;
110+ const fixture = ( await fsp . readFile ( file , "utf8" ) )
111+ . toString ( )
112+ . replaceAll ( "\r\n" , "\n" ) ;
113+ const delimiterIndex = fixture . match ( / ^ - - - $ / m) ?. index ;
114+
115+ assert . isDefined (
116+ delimiterIndex ,
117+ "Can't find delimiter '---' in scope fixture" ,
118+ ) ;
119+
120+ const code = fixture . slice ( 0 , delimiterIndex ! - 1 ) ;
121+
122+ await openNewEditor ( code , { languageId } ) ;
123+
124+ const editor = ide . activeTextEditor ! ;
125+
126+ if ( editor == null ) {
127+ console . log ( "editor" == null ) ;
128+ }
129+
130+ if ( ! scopeProvider && ! scopeType && ! isIteration ) {
131+ console . log ( "weird" ) ;
132+ }
133+
134+ // const outputFixture = ((): string => {
135+ // const config = {
136+ // visibleOnly: false,
137+ // scopeType,
138+ // };
139+
140+ // if (isIteration) {
141+ // const iterationScopes = scopeProvider.provideIterationScopeRanges(
142+ // editor,
143+ // {
144+ // ...config,
145+ // includeNestedTargets: false,
146+ // },
147+ // );
148+ // return serializeIterationScopeFixture(code, iterationScopes);
143149 // }
144- // } catch (error) {
145- // console.log(`Error running test for ${facetId} in ${languageId}`);
146- // console.log(error);
147- // }
150+
151+ // const scopes = scopeProvider.provideScopeRanges(editor, config);
152+
153+ // return serializeScopeFixture(facetId, code, scopes);
154+ // })();
148155
149156 assert . ok ( true ) ;
150157
@@ -155,28 +162,28 @@ async function runTest(file: string, languageId: string, facetId: string) {
155162 // }
156163}
157164
158- // function getFacetInfo(
159- // languageId: string,
160- // facetId: string,
161- // ): {
162- // scopeType: ScopeType;
163- // isIteration: boolean;
164- // } {
165- // const facetInfo =
166- // languageId === "textual"
167- // ? textualScopeSupportFacetInfos[facetId as TextualScopeSupportFacet]
168- // : scopeSupportFacetInfos[facetId as ScopeSupportFacet];
169-
170- // if (facetInfo == null) {
171- // throw Error(`Missing scope support facet info for: ${facetId}`);
172- // }
173-
174- // const { scopeType, isIteration } = facetInfo;
175- // const fullScopeType =
176- // typeof scopeType === "string" ? { type: scopeType } : scopeType;
177-
178- // return {
179- // scopeType: fullScopeType,
180- // isIteration: isIteration ?? false,
181- // };
182- // }
165+ function getFacetInfo (
166+ languageId : string ,
167+ facetId : string ,
168+ ) : {
169+ scopeType : ScopeType ;
170+ isIteration : boolean ;
171+ } {
172+ const facetInfo =
173+ languageId === "textual"
174+ ? textualScopeSupportFacetInfos [ facetId as TextualScopeSupportFacet ]
175+ : scopeSupportFacetInfos [ facetId as ScopeSupportFacet ] ;
176+
177+ if ( facetInfo == null ) {
178+ throw Error ( `Missing scope support facet info for: ${ facetId } ` ) ;
179+ }
180+
181+ const { scopeType, isIteration } = facetInfo ;
182+ const fullScopeType =
183+ typeof scopeType === "string" ? { type : scopeType } : scopeType ;
184+
185+ return {
186+ scopeType : fullScopeType ,
187+ isIteration : isIteration ?? false ,
188+ } ;
189+ }
0 commit comments