1- import type {
2- Disposable ,
3- EnforceUndefined ,
4- IDE ,
5- Range ,
6- ScopeProvider ,
7- ScopeType ,
8- TextDocument ,
9- TreeSitter ,
10- } from "@cursorless/common" ;
1+ import type { EnforceUndefined } from "@cursorless/common" ;
112import {
123 FakeCommandServerApi ,
134 FakeIDE ,
@@ -27,36 +18,22 @@ import {
2718 ScopeTestRecorder ,
2819 TestCaseRecorder ,
2920} from "@cursorless/test-case-recorder" ;
30- import type { CursorlessApi , ParseTreeApi } from "@cursorless/vscode-common" ;
21+ import type { CursorlessApi } from "@cursorless/vscode-common" ;
3122import {
3223 getCommandServerApi ,
3324 getParseTreeApi ,
34- toVscodeRange ,
3525} from "@cursorless/vscode-common" ;
36- import * as crypto from "crypto" ;
37- import { pull } from "lodash-es" ;
38- import * as os from "node:os" ;
39- import * as path from "node:path" ;
40- import * as vscode from "vscode" ;
26+ import type { ExtensionContext } from "vscode" ;
4127import { InstallationDependencies } from "./InstallationDependencies" ;
4228import { ReleaseNotes } from "./ReleaseNotes" ;
4329import { ScopeTreeProvider } from "./ScopeTreeProvider" ;
44- import type {
45- ScopeVisualizer ,
46- ScopeVisualizerListener ,
47- VisualizationType ,
48- } from "./ScopeVisualizerCommandApi" ;
4930import { StatusBarItem } from "./StatusBarItem" ;
5031import { VscodeSnippets } from "./VscodeSnippets" ;
5132import { constructTestHelpers } from "./constructTestHelpers" ;
33+ import { createScopeVisualizer } from "./createScopeVisualizer" ;
34+ import { createTreeSitter } from "./createTreeSitter" ;
5235import { createTutorial } from "./createTutorial" ;
53- import type { VscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer" ;
54- import { createVscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer" ;
55- import { VscodeFileSystem } from "./ide/vscode/VscodeFileSystem" ;
56- import { VscodeIDE } from "./ide/vscode/VscodeIDE" ;
57- import { FakeFontMeasurements } from "./ide/vscode/hats/FakeFontMeasurements" ;
58- import { FontMeasurementsImpl } from "./ide/vscode/hats/FontMeasurementsImpl" ;
59- import { VscodeHats } from "./ide/vscode/hats/VscodeHats" ;
36+ import { createVscodeIde } from "./createVscodeIde" ;
6037import { KeyboardCommands } from "./keyboard/KeyboardCommands" ;
6138import { registerCommands } from "./registerCommands" ;
6239import { revisualizeOnCustomRegexChange } from "./revisualizeOnCustomRegexChange" ;
@@ -72,9 +49,10 @@ import { vscodeApi } from "./vscodeApi";
7249 * - Creates an entrypoint for running commands {@link CommandRunner}.
7350 */
7451export async function activate (
75- context : vscode . ExtensionContext ,
52+ context : ExtensionContext ,
7653) : Promise < CursorlessApi > {
7754 const parseTreeApi = await getParseTreeApi ( ) ;
55+ const treeSitter = createTreeSitter ( parseTreeApi ) ;
7856
7957 const { vscodeIDE, hats, fileSystem } = await createVscodeIde ( context ) ;
8058 const isTesting = vscodeIDE . runMode === "test" ;
@@ -89,7 +67,6 @@ export async function activate(
8967 ? fakeCommandServerApi
9068 : await getCommandServerApi ( ) ;
9169
92- const treeSitter = createTreeSitter ( parseTreeApi ) ;
9370 const talonSpokenForms = new FileSystemTalonSpokenForms ( fileSystem ) ;
9471
9572 const snippets = new VscodeSnippets ( normalizedIde ) ;
@@ -212,105 +189,3 @@ export async function activate(
212189 : undefined ,
213190 } ;
214191}
215-
216- async function createVscodeIde ( context : vscode . ExtensionContext ) {
217- const vscodeIDE = new VscodeIDE ( context ) ;
218-
219- const hats = new VscodeHats (
220- vscodeIDE ,
221- vscodeApi ,
222- context ,
223- vscodeIDE . runMode === "test"
224- ? new FakeFontMeasurements ( )
225- : new FontMeasurementsImpl ( context ) ,
226- ) ;
227- await hats . init ( ) ;
228-
229- // FIXME: Inject this from test harness. Would need to arrange to delay
230- // extension initialization, probably by returning a function from extension
231- // init that has parameters consisting of test configuration, and have that
232- // function do the actual initialization.
233- const cursorlessDir =
234- vscodeIDE . runMode === "test"
235- ? path . join ( os . tmpdir ( ) , crypto . randomBytes ( 16 ) . toString ( "hex" ) )
236- : path . join ( os . homedir ( ) , ".cursorless" ) ;
237-
238- const fileSystem = new VscodeFileSystem (
239- context ,
240- vscodeIDE . runMode ,
241- cursorlessDir ,
242- ) ;
243- await fileSystem . initialize ( ) ;
244-
245- return { vscodeIDE, hats, fileSystem } ;
246- }
247-
248- function createTreeSitter ( parseTreeApi : ParseTreeApi ) : TreeSitter {
249- return {
250- getNodeAtLocation ( document : TextDocument , range : Range ) {
251- return parseTreeApi . getNodeAtLocation (
252- new vscode . Location ( document . uri , toVscodeRange ( range ) ) ,
253- ) ;
254- } ,
255-
256- getTree ( document : TextDocument ) {
257- return parseTreeApi . getTreeForUri ( document . uri ) ;
258- } ,
259-
260- loadLanguage : parseTreeApi . loadLanguage ,
261- createQuery : parseTreeApi . createQuery ,
262- } ;
263- }
264-
265- function createScopeVisualizer (
266- ide : IDE ,
267- scopeProvider : ScopeProvider ,
268- ) : ScopeVisualizer {
269- let scopeVisualizer : VscodeScopeVisualizer | undefined ;
270- let currentScopeType : ScopeType | undefined ;
271-
272- const listeners : ScopeVisualizerListener [ ] = [ ] ;
273-
274- return {
275- start ( scopeType : ScopeType , visualizationType : VisualizationType ) {
276- scopeVisualizer ?. dispose ( ) ;
277- scopeVisualizer = createVscodeScopeVisualizer (
278- ide ,
279- scopeProvider ,
280- scopeType ,
281- visualizationType ,
282- ) ;
283- scopeVisualizer . start ( ) ;
284- currentScopeType = scopeType ;
285- listeners
286- . slice ( )
287- . forEach ( ( listener ) => listener ( scopeType , visualizationType ) ) ;
288- } ,
289-
290- stop ( ) {
291- scopeVisualizer ?. dispose ( ) ;
292- scopeVisualizer = undefined ;
293- currentScopeType = undefined ;
294- listeners . slice ( ) . forEach ( ( listener ) => listener ( undefined , undefined ) ) ;
295- } ,
296-
297- get scopeType ( ) {
298- return currentScopeType ;
299- } ,
300-
301- onDidChangeScopeType ( listener : ScopeVisualizerListener ) : Disposable {
302- listeners . push ( listener ) ;
303-
304- return {
305- dispose ( ) {
306- pull ( listeners , listener ) ;
307- } ,
308- } ;
309- } ,
310- } ;
311- }
312-
313- // this method is called when your extension is deactivated
314- export function deactivate ( ) {
315- // do nothing
316- }
0 commit comments