Skip to content

Commit

Permalink
feat: only include .md, .html files when which explicitly added i…
Browse files Browse the repository at this point in the history
…n tsconfig inlcude

close #1463
  • Loading branch information
johnsoncodehk committed Jun 16, 2022
1 parent 49ded22 commit 66083fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/alpine-language-server/src/node.ts
Expand Up @@ -20,8 +20,8 @@ createLanguageServer(connection, {
onDidChangeConfiguration(settings) { },
fileSystemProvide: undefined,
}, {
projectExts: ['.html'],
inferProjectExts: [],
definitelyExts: ['.html'],
indeterminateExts: [],
getDocumentService: (mods, configHost, _, plugins) => alpine.getDocumentService(mods, configHost, plugins),
createLanguageService: (mods, lsHost, _1, _2, configHost, plugins) => alpine.createLanguageService(mods, lsHost, configHost, plugins),
});
2 changes: 1 addition & 1 deletion packages/typescript-vue-plugin/src/index.ts
Expand Up @@ -193,7 +193,7 @@ function createProxyHost(ts: typeof import('typescript/lib/tsserverlibrary'), in
const parseConfigHost: ts.ParseConfigHost = {
useCaseSensitiveFileNames: info.project.useCaseSensitiveFileNames(),
readDirectory: (path, extensions, exclude, include, depth) => {
return info.project.readDirectory(path, ['.vue', '.md', '.html'], exclude, include, depth);
return info.project.readDirectory(path, ['.vue'], exclude, include, depth);
},
fileExists: fileName => info.project.fileExists(fileName),
readFile: fileName => info.project.readFile(fileName),
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-language-server/src/common.ts
Expand Up @@ -17,8 +17,8 @@ export interface RuntimeEnvironment {
}

export interface LanguageConfigs {
projectExts: string[],
inferProjectExts: string[],
definitelyExts: string[],
indeterminateExts: string[],
getDocumentService: typeof vue.getDocumentService,
createLanguageService: typeof vue.createLanguageService,
}
Expand All @@ -27,8 +27,8 @@ export function createLanguageServer(
connection: vscode.Connection,
runtimeEnv: RuntimeEnvironment,
languageConfigs: LanguageConfigs = {
projectExts: ['.vue', '.md', '.html'],
inferProjectExts: ['.vue'],
definitelyExts: ['.vue'],
indeterminateExts: ['.md', '.html'],
getDocumentService: vue.getDocumentService,
createLanguageService: vue.createLanguageService,
},
Expand Down
Expand Up @@ -290,7 +290,7 @@ export function register(
connection.workspace.onWillRenameFiles(async handler => {

const hasTsFile = handler.files.some(file =>
languageConfigs.projectExts.some(ext => file.oldUri.endsWith(ext))
languageConfigs.definitelyExts.some(ext => file.oldUri.endsWith(ext))
|| file.newUri.endsWith('.ts')
|| file.newUri.endsWith('.tsx')
);
Expand Down
13 changes: 10 additions & 3 deletions packages/vue-language-server/src/project.ts
Expand Up @@ -241,17 +241,24 @@ export async function createProject(
scripts.clear();
}
function createParsedCommandLine(): ReturnType<typeof tsShared.createParsedCommandLine> {
const extraExts = typeof tsConfig === 'string' ? languageConfigs.projectExts : languageConfigs.inferProjectExts;
const parseConfigHost: ts.ParseConfigHost = {
useCaseSensitiveFileNames: projectSys.useCaseSensitiveFileNames,
readDirectory: (path, extensions, exclude, include, depth) => {
return projectSys.readDirectory(path, [...extensions, ...extraExts], exclude, include, depth);
const exts = [...extensions, ...languageConfigs.definitelyExts];
for (const passiveExt of languageConfigs.indeterminateExts) {
if (include.some(i => i.endsWith(passiveExt))) {
exts.push(passiveExt);
}
}
return projectSys.readDirectory(path, exts, exclude, include, depth);
},
fileExists: projectSys.fileExists,
readFile: projectSys.readFile,
};
if (typeof tsConfig === 'string') {
return tsShared.createParsedCommandLine(ts, parseConfigHost, tsConfig);
const r = tsShared.createParsedCommandLine(ts, parseConfigHost, tsConfig);
console.log(r.fileNames);
return r;
}
else {
const content = ts.parseJsonConfigFileContent({}, parseConfigHost, rootPath, tsConfig, 'tsconfig.json');
Expand Down
Expand Up @@ -37,7 +37,7 @@ export function register(
fileOperations: {
willRename: {
filters: [
...languageConfigs.inferProjectExts.map(ext => ({ pattern: { glob: `**/*${ext}` } })),
...[...languageConfigs.definitelyExts, ...languageConfigs.indeterminateExts].map(ext => ({ pattern: { glob: `**/*${ext}` } })),
{ pattern: { glob: '**/*.js' } },
{ pattern: { glob: '**/*.ts' } },
{ pattern: { glob: '**/*.jsx' } },
Expand Down

0 comments on commit 66083fc

Please sign in to comment.