Skip to content

Commit

Permalink
Re-write extension to use reactive-vscode, align with Vue extension (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
machty authored Jan 16, 2025
1 parent 177f757 commit 8a1788a
Show file tree
Hide file tree
Showing 11 changed files with 718 additions and 185 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dist/
!/packages/environment*/-private/dsl/**/*.d.ts
!/packages/environment*/-private/intrinsics/**/*.d.ts

/packages/vscode/src/generated-meta.ts

# Markdown files: the formatting Prettier uses by default *does. not. match.*
# the formatting applied by Gitbook. Having both present is a recipe for ongoing
# CI problems.
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
lib/
dist/
tsconfig.tsbuildinfo

generated-meta.ts
12 changes: 5 additions & 7 deletions packages/vscode/__tests__/support/launch-from-cli.mts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as path from 'node:path';
import * as os from 'node:os';
import { fileURLToPath } from 'node:url';
import { runTests } from '@vscode/test-electron';
import * as fs from 'node:fs';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.resolve(dirname, '../../..');
const packageRoot = path.resolve(process.cwd());
const emptyExtensionsDir = path.join(os.tmpdir(), `extensions-${Math.random()}`);
const emptyUserDataDir = path.join(os.tmpdir(), `user-data-${Math.random()}`);

Expand All @@ -28,13 +26,13 @@ let disableExtensionArgs: string[] = [];
let testRunner: string;
switch (testType) {
case 'language-server':
testRunner = 'vscode-runner-language-server.js';
testRunner = 'lib/__tests__/support/vscode-runner-language-server.js';

// Disable vanilla TS for full "takeover" mode.
disableExtensionArgs = ['--disable-extension', 'vscode.typescript-language-features'];
break;
case 'ts-plugin':
testRunner = 'vscode-runner-ts-plugin.js';
testRunner = 'lib/__tests__/support/vscode-runner-ts-plugin.js';

// Note: here, we WANT vanilla TS to be enabled since we're testing the TS Plugin.
break;
Expand All @@ -44,9 +42,9 @@ switch (testType) {
}

try {
await runTests({
runTests({
extensionDevelopmentPath: packageRoot,
extensionTestsPath: path.resolve(dirname, testRunner),
extensionTestsPath: path.resolve(process.cwd(), testRunner),
launchArgs: [
// Don't show the "hey do you trust this folder?" prompt
'--disable-workspace-trust',
Expand Down
51 changes: 41 additions & 10 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"bundle": "node ./scripts/build.mjs",
"bundle:watch": "node ./scripts/build.mjs -- --watch",
"extension:package": "vsce package --no-dependencies",
"extension:publish": "vsce publish --no-dependencies"
"extension:publish": "vsce publish --no-dependencies",
"postinstall": "vscode-ext-gen --scope glint",
"prebuild": "vscode-ext-gen --scope glint"
},
"engines": {
"vscode": "^1.68.1"
Expand Down Expand Up @@ -188,6 +190,7 @@
],
"configuration": [
{
"type": "object",
"title": "Glint",
"properties": {
"glint.libraryPath": {
Expand All @@ -205,18 +208,44 @@
"verbose"
]
},
"glint.server.typescriptMode": {
"type": "string",
"default": "languageServer",
"glint.server.hybridMode": {
"type": [
"boolean",
"string"
],
"default": "auto",
"enum": [
"languageServer",
"typescriptPlugin"
"auto",
"typeScriptPluginOnly",
true,
false
],
"enumDescriptions": [
"(Old) use Glint Language Server for typechecking",
"(New) Use TypeScript server plugin for typechecking"
"Automatically detect and enable TypeScript Plugin/Hybrid Mode in a safe environment.",
"Only enable Glint TypeScript Plugin but disable the Glint language server.",
"Enable TypeScript Plugin/Hybrid Mode.",
"Disable TypeScript Plugin/Hybrid Mode."
],
"description": "Glint 2 shifts typechecking to a TypeScript server plugin. This setting allows you to opt into the new behavior."
"description": "Hybrid mode means that Glint will use a TypeScript server plugin for typechecking and use the Glint language server for other features. This is the recommended mode."
},
"glint.server.compatibleExtensions": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Set compatible extensions to skip automatic detection of Hybrid Mode."
},
"glint.server.includeLanguages": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"glimmer-js",
"glimmer-ts",
"handlebars"
]
}
}
}
Expand All @@ -241,7 +270,9 @@
"esbuild": "^0.15.16",
"expect": "^29.5.0",
"glob": "^10.2.4",
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"reactive-vscode": "0.2.7-beta.1",
"vscode-ext-gen": "^0.5.0"
},
"volta": {
"extends": "../../package.json"
Expand Down
63 changes: 63 additions & 0 deletions packages/vscode/src/compatibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { computed, useAllExtensions } from 'reactive-vscode';
import * as semver from 'semver';
import * as vscode from 'vscode';
import { config } from './config';

// TODO: does Glint need this concept of "compatible" extensions?

const defaultCompatibleExtensions = new Set([
'astro-build.astro-vscode',
'bierner.lit-html',
'Divlo.vscode-styled-jsx-languageserver',
'GitHub.copilot-chat',
'ije.esm-vscode',
'jenkey2011.string-highlight',
'johnsoncodehk.vscode-tsslint',
'kimuson.ts-type-expand',
'miaonster.vscode-tsx-arrow-definition',
'ms-dynamics-smb.al',
'mxsdev.typescript-explorer',
'nrwl.angular-console',
'p42ai.refactor',
'runem.lit-plugin',
'ShenQingchuan.vue-vine-extension',
'styled-components.vscode-styled-components',
'unifiedjs.vscode-mdx',
'VisualStudioExptTeam.vscodeintellicode',
'Vue.volar',
]);

const extensions = useAllExtensions();

export const incompatibleExtensions = computed(() => {
return extensions.value
.filter((ext) => isExtensionCompatibleWithHybridMode(ext) === false)
.map((ext) => ext.id);
});

export const unknownExtensions = computed(() => {
return extensions.value
.filter(
(ext) =>
isExtensionCompatibleWithHybridMode(ext) === undefined &&
!!ext.packageJSON?.contributes?.typescriptServerPlugins,
)
.map((ext) => ext.id);
});

function isExtensionCompatibleWithHybridMode(
extension: vscode.Extension<any>,
): boolean | undefined {
if (
defaultCompatibleExtensions.has(extension.id) ||
config.server.compatibleExtensions.includes(extension.id)
) {
return true;
}
if (extension.id === 'denoland.vscode-deno') {
return !vscode.workspace.getConfiguration('deno').get<boolean>('enable');
}
if (extension.id === 'svelte.svelte-vscode') {
return semver.gte(extension.packageJSON.version, '108.4.0');
}
}
7 changes: 7 additions & 0 deletions packages/vscode/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfigObject } from 'reactive-vscode';
import { NestedScopedConfigs, scopedConfigs } from './generated-meta';

export const config = defineConfigObject<NestedScopedConfigs>(
scopedConfigs.scope,
scopedConfigs.defaults,
);
Loading

0 comments on commit 8a1788a

Please sign in to comment.