Skip to content

Commit

Permalink
rm glint/getIR command
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jun 26, 2024
1 parent ac03de6 commit 8e9b9b0
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 124 deletions.
14 changes: 0 additions & 14 deletions packages/core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,13 @@ 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()
.parseSync();

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.
Expand Down
27 changes: 0 additions & 27 deletions packages/core/src/language-server/messages.cts
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
import { ProtocolRequestType, TextEdit } from '@volar/language-server';

export type Request<Name extends string, T> = {
name: Name;
type: T;
};

export const GetIRRequest = makeRequestType(
'glint/getIR',
ProtocolRequestType<GetIRParams, GetIRResult | null, void, void, void>,
);

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 extends string, T>(
name: Name,
RequestType: new (name: Name) => T,
): Request<Name, T> {
return { name, type: new RequestType(name) };
}
2 changes: 0 additions & 2 deletions packages/core/src/transform/template/rewrite-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 0 additions & 24 deletions packages/vscode/__tests__/smoketest-ember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
12 changes: 0 additions & 12 deletions packages/vscode/__tests__/smoketest-template-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
10 changes: 0 additions & 10 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
35 changes: 0 additions & 35 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -78,32 +76,6 @@ async function restartClients(): Promise<void> {
await Promise.all([...clients.values()].map((client) => client.restart()));
}

async function showDebugIR(editor: TextEditor): Promise<void> {
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<typeof GetIRRequest>('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

Expand Down Expand Up @@ -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<R extends Request<string, unknown>>(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 {
Expand Down

0 comments on commit 8e9b9b0

Please sign in to comment.