From 8e9b9b0da236626aab192ed08b42cb9b93d84b63 Mon Sep 17 00:00:00 2001 From: machty Date: Wed, 26 Jun 2024 16:29:00 -0400 Subject: [PATCH] rm glint/getIR command --- packages/core/src/cli/index.ts | 14 -------- .../core/src/language-server/messages.cts | 27 -------------- .../src/transform/template/rewrite-module.ts | 2 -- .../vscode/__tests__/smoketest-ember.test.ts | 24 ------------- .../smoketest-template-imports.test.ts | 12 ------- packages/vscode/package.json | 10 ------ packages/vscode/src/extension.ts | 35 ------------------- 7 files changed, 124 deletions(-) diff --git a/packages/core/src/cli/index.ts b/packages/core/src/cli/index.ts index e40ae300d..c3f26f51d 100644 --- a/packages/core/src/cli/index.ts +++ b/packages/core/src/cli/index.ts @@ -65,10 +65,6 @@ const argv = yargs(process.argv.slice(2)) 'Save .tsbuildinfo files to allow for incremental compilation of projects. Same as the TS `--incremental` flag.', type: 'boolean', }) - .option('debug-intermediate-representation', { - boolean: false, - description: `When true, writes out a Glint's internal intermediate representation of each file within a GLINT_DEBUG subdirectory of the current working directory. This is intended for debugging Glint itself.`, - }) .version(pkg.version) .wrap(100) .strict() @@ -76,16 +72,6 @@ const argv = yargs(process.argv.slice(2)) let cwd = process.cwd(); -if (argv['debug-intermediate-representation']) { - const fs = require('fs'); - const path = require('path'); - (globalThis as any).GLINT_DEBUG_IR = function (filename: string, content: string) { - let target = path.join('GLINT_DEBUG', path.relative(cwd, filename)); - fs.mkdirSync(path.dirname(target), { recursive: true }); - fs.writeFileSync(target, content); - }; -} - if (argv.build) { // Type signature here so we get a useful error as close to the source of the // error as possible, rather than at the *use* sites below. diff --git a/packages/core/src/language-server/messages.cts b/packages/core/src/language-server/messages.cts index 64a8cef54..f92819c49 100644 --- a/packages/core/src/language-server/messages.cts +++ b/packages/core/src/language-server/messages.cts @@ -1,31 +1,4 @@ -import { ProtocolRequestType, TextEdit } from '@volar/language-server'; - export type Request = { name: Name; type: T; }; - -export const GetIRRequest = makeRequestType( - 'glint/getIR', - ProtocolRequestType, -); - -export interface GetIRParams { - uri: string; -} - -export interface GetIRResult { - contents: string; - uri: string; -} - -// This utility allows us to encode type information to enforce that we're using -// a valid request name along with its associated param/response types without -// actually requring the runtime code here to be imported elsewhere. -// See `requestKey` in the Code extension. -function makeRequestType( - name: Name, - RequestType: new (name: Name) => T, -): Request { - return { name, type: new RequestType(name) }; -} diff --git a/packages/core/src/transform/template/rewrite-module.ts b/packages/core/src/transform/template/rewrite-module.ts index 1512ed976..b3488083f 100644 --- a/packages/core/src/transform/template/rewrite-module.ts +++ b/packages/core/src/transform/template/rewrite-module.ts @@ -49,8 +49,6 @@ export function rewriteModule( let sparseSpans = completeCorrelatedSpans(partialSpans); let { contents, correlatedSpans } = calculateTransformedSource(script, sparseSpans); - (globalThis as any).GLINT_DEBUG_IR?.(script.filename, contents); - return new TransformedModule(contents, errors, directives, correlatedSpans); } diff --git a/packages/vscode/__tests__/smoketest-ember.test.ts b/packages/vscode/__tests__/smoketest-ember.test.ts index 94bc761a3..ac7811e91 100644 --- a/packages/vscode/__tests__/smoketest-ember.test.ts +++ b/packages/vscode/__tests__/smoketest-ember.test.ts @@ -26,30 +26,6 @@ describe('Smoke test: Ember', () => { } }); - describe('debugging commands', () => { - test('showing IR in the backing file', async () => { - let scriptURI = Uri.file(`${rootDir}/app/components/colocated-layout.ts`); - let editor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); - - await commands.executeCommand('glint.show-debug-ir'); - await waitUntil(() => editor.document.getText().includes('𝚪')); - - expect(editor.document.getText()).toMatch('𝚪.this.message'); - }); - - test('showing IR from a template', async () => { - let templateURI = Uri.file(`${rootDir}/app/components/colocated-layout.hbs`); - let scriptURI = Uri.file(`${rootDir}/app/components/colocated-layout.ts`); - - await window.showTextDocument(templateURI, { viewColumn: ViewColumn.One }); - await commands.executeCommand('glint.show-debug-ir'); - await waitUntil(() => window.activeTextEditor?.document.getText().includes('𝚪')); - - expect(window.activeTextEditor?.document.uri.toString()).toEqual(scriptURI.toString()); - expect(window.activeTextEditor?.document.getText()).toMatch('𝚪.this.message'); - }); - }); - describe('diagnostics for errors', () => { test('component template', async () => { let scriptURI = Uri.file(`${rootDir}/app/components/colocated-layout.ts`); diff --git a/packages/vscode/__tests__/smoketest-template-imports.test.ts b/packages/vscode/__tests__/smoketest-template-imports.test.ts index cdad6ab4c..fce1b27df 100644 --- a/packages/vscode/__tests__/smoketest-template-imports.test.ts +++ b/packages/vscode/__tests__/smoketest-template-imports.test.ts @@ -51,18 +51,6 @@ describe('Smoke test: ETI Environment', () => { ]); }); - describe('debugging commands', () => { - test('showing IR in a custom file type', async () => { - let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`); - let editor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); - - await commands.executeCommand('glint.show-debug-ir'); - await waitUntil(() => editor.document.getText().includes('𝚪')); - - expect(editor.document.getText()).toMatch('𝚪.this.message'); - }); - }); - describe('codeactions args', () => { test('adds missing args from template into Args type', async () => { let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`); diff --git a/packages/vscode/package.json b/packages/vscode/package.json index d378beb0a..4f0578e52 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -178,11 +178,6 @@ { "title": "Glint: Restart Glint Server", "command": "glint.restart-language-server" - }, - { - "title": "Glint: Show IR for Debugging", - "command": "glint.show-debug-ir", - "enablement": "config.glint.debug == true" } ], "menus": { @@ -202,11 +197,6 @@ "order": 1, "type": "string" }, - "glint.debug": { - "description": "Enable debugging commands for Glint.", - "type": "boolean", - "default": false - }, "glint.trace.server": { "description": "Traces communication between VS Code and the Glint language server.", "type": "string", diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 9ba9ec043..d01d64c0f 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -24,7 +24,6 @@ import { } from '@volar/vscode'; import { Disposable, LanguageClient, ServerOptions } from '@volar/vscode/node.js'; -import type { Request, GetIRRequest } from '@glint/core/lsp-messages'; /////////////////////////////////////////////////////////////////////////////// // Setup and extension lifecycle @@ -43,7 +42,6 @@ export function activate(context: ExtensionContext): LabsInfo { context.subscriptions.push(fileWatcher, createConfigWatcher()); context.subscriptions.push( commands.registerCommand('glint.restart-language-server', restartClients), - commands.registerTextEditorCommand('glint.show-debug-ir', showDebugIR), ); // TODO: how to each multiple workspace reloads with VolarLabs? @@ -78,32 +76,6 @@ async function restartClients(): Promise { await Promise.all([...clients.values()].map((client) => client.restart())); } -async function showDebugIR(editor: TextEditor): Promise { - let workspaceFolder = workspace.getWorkspaceFolder(editor.document.uri); - if (!workspaceFolder) { - return; - } - - let sourceURI = editor.document.uri; - let client = clients.get(workspaceFolder.uri.fsPath); - let request = requestKey('glint/getIR'); - let response = await client?.sendRequest(request, { uri: sourceURI.toString() }); - - // Just don't support this command for older @glint/core versions - if (!response || typeof response === 'string') return; - - let { contents, uri } = response; - let targetEditor = await window.showTextDocument(Uri.parse(uri)); - let { document } = targetEditor; - - let start = document.positionAt(0); - let end = document.positionAt(document.getText().length); - - await targetEditor.edit((edit) => { - edit.replace(new Range(start, end), contents); - }); -} - /////////////////////////////////////////////////////////////////////////////// // Workspace folder management @@ -216,13 +188,6 @@ function createConfigWatcher(): Disposable { return configWatcher; } -// This allows us to just use a bare string key for performing a request while maintaining -// type information for the request _without_ forcing us to import runtime code from -// `@glint/core` into the extension. -function requestKey>(name: R['name']): R['type'] { - return name as unknown as R['type']; -} - // Loads the TypeScript and JavaScript formating options from the workspace and subsets them to // pass to the language server. function getOptions(config: WorkspaceConfiguration, key: string): object {