Skip to content

Commit

Permalink
feat: add Pug tools (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jan 3, 2023
1 parent cda8551 commit 01ed6a1
Show file tree
Hide file tree
Showing 44 changed files with 509 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -22,6 +22,6 @@ jobs:

# install pnpm
- run: npm i -g pnpm
- run: pnpm install --frozen-lockfile --no-optional --filter "." --filter "./packages/**" --filter "./plugins/**" --filter "./vue-language-tools/**"
- run: pnpm install --frozen-lockfile --no-optional
- run: pnpm run build-ci
- run: pnpm run test
17 changes: 17 additions & 0 deletions .vscode/launch.json
Expand Up @@ -19,6 +19,23 @@
"script": "watch"
}
},
{
"name": "Launch Pug",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}/pug-language-tools/vscode-pug"
],
"outFiles": [
"${workspaceRoot}/*/*/out/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"name": "Launch Svelte Example",
"type": "extensionHost",
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Expand Up @@ -6,6 +6,7 @@
"extensions/*",
"packages/*",
"plugins/*",
"pug-language-tools/*",
"vue-language-tools/*"
],
"version": "1.0.19"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -9,10 +9,11 @@
"watch:typescript-vue-plugin": "cd ./extensions/vscode-typescript-vue-plugin && npm run watch",
"prerelease": "npm run build && npm run test",
"version:test": "lerna version --exact --force-publish --yes --sync-workspace-lock --no-push --no-git-tag-version",
"release": "npm run release:base && npm run release:vue-language-features && npm run release:typescript-vue-plugin",
"release": "npm run release:base && npm run release:vue && npm run release:pug && npm run release:typescript-vue-plugin",
"release:base": "lerna publish --exact --force-publish --yes --sync-workspace-lock",
"release:base-next": "lerna publish --exact --force-publish --yes --sync-workspace-lock --dist-tag next",
"release:vue-language-features": "cd ./extensions/vscode-vue-language-features && npm run release",
"release:vue": "cd ./extensions/vscode-vue-language-features && npm run release",
"release:pug": "cd ./pug-language-tools/vscode-pug && npm run release",
"release:typescript-vue-plugin": "cd ./extensions/vscode-typescript-vue-plugin && npm run release",
"test": "vitest run",
"docs:dev": "cd docs && npm run dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/common/project.ts
Expand Up @@ -271,7 +271,7 @@ function createParsedCommandLine(
tsConfig: path.PosixPath | ts.CompilerOptions,
plugins: ReturnType<LanguageServerPlugin>[],
): ts.ParsedCommandLine {
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions).flat();
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
try {
let content: ts.ParsedCommandLine;
if (typeof tsConfig === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/common/server.ts
Expand Up @@ -99,7 +99,7 @@ export function createCommonLanguageServer(context: ServerContext) {
'jsx',
'tsx',
'json',
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ext.extension)).flat(),
...plugins.map(plugin => plugin.extraFileExtensions?.map(ext => ext.extension) ?? []).flat(),
].join(',')}}`
},
]
Expand Down
44 changes: 31 additions & 13 deletions packages/language-server/src/common/utils/registerFeatures.ts
Expand Up @@ -133,11 +133,23 @@ export function setupCapabilities(
if (!initOptions.respectClientCapabilities || params.textDocument?.inlayHint) {
server.inlayHintProvider = true;
}
if (!initOptions.respectClientCapabilities || params.textDocument?.diagnostic && (initOptions.diagnosticModel ?? DiagnosticModel.Push) === DiagnosticModel.Pull) {
if ((!initOptions.respectClientCapabilities || params.textDocument?.diagnostic) && (initOptions.diagnosticModel ?? DiagnosticModel.Push) === DiagnosticModel.Pull) {
server.diagnosticProvider = {
documentSelector: [
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: `**/*.${ext.extension}` }))).flat(),
{ pattern: '**/*.{ts,js,tsx,jsx}' },
{
pattern: `**/*.{${[
'js',
'cjs',
'mjs',
'ts',
'cts',
'mts',
'jsx',
'tsx',
// 'json',
...plugins.map(plugin => plugin.extraFileExtensions?.map(ext => ext.extension) ?? []).flat(),
].join(',')}}`
}
],
interFileDependencies: true,
workspaceDiagnostics: false,
Expand All @@ -150,16 +162,22 @@ export function setupCapabilities(
fileOperations: {
willRename: {
filters: [
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: { glob: `**/*.${ext.extension}` } }))).flat(),
{ pattern: { glob: '**/*.js' } },
{ pattern: { glob: '**/*.cjs' } },
{ pattern: { glob: '**/*.mjs' } },
{ pattern: { glob: '**/*.ts' } },
{ pattern: { glob: '**/*.cts' } },
{ pattern: { glob: '**/*.mts' } },
{ pattern: { glob: '**/*.jsx' } },
{ pattern: { glob: '**/*.tsx' } },
{ pattern: { glob: '**/*.json' } },
{
pattern: {
glob: `**/*.{${[
'js',
'cjs',
'mjs',
'ts',
'cts',
'mts',
'jsx',
'tsx',
'json',
...plugins.map(plugin => plugin.extraFileExtensions?.map(ext => ext.extension) ?? []).flat(),
].join(',')}}`
}
},
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/types.ts
Expand Up @@ -41,7 +41,7 @@ export type LanguageServerPlugin<
C = embeddedLS.LanguageService
> = (initOptions: A) => {

extraFileExtensions: ts.FileExtensionInfo[];
extraFileExtensions?: ts.FileExtensionInfo[];

resolveLanguageServiceHost?(
ts: typeof import('typescript/lib/tsserverlibrary'),
Expand Down
3 changes: 3 additions & 0 deletions plugins/pug/src/index.ts
Expand Up @@ -48,6 +48,7 @@ export default function (): LanguageServicePlugin & ReturnType<typeof useHtmlPlu
if (pugDocument.error) {

return [{
source: 'pug',
code: pugDocument.error.code,
message: pugDocument.error.msg,
range: {
Expand All @@ -56,6 +57,8 @@ export default function (): LanguageServicePlugin & ReturnType<typeof useHtmlPlu
},
}];
}

return [];
});
},
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/pug/tsconfig.build.json
Expand Up @@ -16,7 +16,7 @@
"path": "../../packages/language-service/tsconfig.build.json"
},
{
"path": "../../packages/pug-language-service/tsconfig.build.json"
"path": "../../pug-language-tools/pug-language-service/tsconfig.build.json"
},
],
}

0 comments on commit 01ed6a1

Please sign in to comment.