Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extentions to settings #2759

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface VLSConfig {
experimental: {
templateInterpolationService: boolean;
};
extensions: string[];
};
}

Expand Down Expand Up @@ -140,7 +141,8 @@ export function getDefaultVLSConfig(): VLSFullConfig {
},
experimental: {
templateInterpolationService: false
}
},
extensions: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can call alias.extensions

},
css: {},
html: {
Expand Down
11 changes: 3 additions & 8 deletions server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ import { getComponentInfo } from './componentInfo';
import { DependencyService, RuntimeLibrary } from '../../services/dependencyService';
import { CodeActionData, CodeActionDataKind, OrganizeImportsActionData, RefactorActionData } from '../../types';
import { IServiceHost } from '../../services/typescriptService/serviceHost';
import {
isVirtualVueTemplateFile,
isVueFile,
toCompletionItemKind,
toSymbolKind
} from '../../services/typescriptService/util';
import { isVirtualVueTemplateFile, toCompletionItemKind, toSymbolKind } from '../../services/typescriptService/util';
import * as Previewer from './previewer';
import { isVCancellationRequested, VCancellationToken } from '../../utils/cancellationToken';
import { EnvironmentService } from '../../services/EnvironmentService';
Expand Down Expand Up @@ -755,7 +750,7 @@ export async function getJavascriptMode(
return [];
}

const oldFileIsVue = isVueFile(oldPath);
const oldFileIsVue = env.isVueFile(oldPath);
const formatSettings: ts.FormatCodeSettings = getFormatCodeSettings(env.getConfig());
const preferences = getUserPreferencesByLanguageId(
(sourceFile as any).scriptKind === tsModule.ScriptKind.JS ? 'javascript' : 'typescript'
Expand All @@ -773,7 +768,7 @@ export async function getJavascriptMode(
continue;
}
const doc = getSourceDoc(fileName, program);
const bothNotVueFile = !oldFileIsVue && !isVueFile(fileName);
const bothNotVueFile = !oldFileIsVue && !env.isVueFile(fileName);
if (bothNotVueFile) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion server/src/services/EnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface EnvironmentService {
getVueVersion(): VueVersion;
getSnippetFolder(): string;
getGlobalComponentInfos(): BasicComponentInfo[];
isVueFile(path: string): boolean;
}

export function createEnvironmentService(
Expand All @@ -35,6 +36,7 @@ export function createEnvironmentService(
getPackagePath: () => packagePath,
getVueVersion: () => inferVueVersion(packagePath),
getSnippetFolder: () => snippetFolder,
getGlobalComponentInfos: () => globalComponentInfos
getGlobalComponentInfos: () => globalComponentInfos,
isVueFile: (path: string) => ['.vue', ...$config.vetur.extensions].some(ext => path.endsWith(ext))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you need to prefix . when no dot input.

};
}
8 changes: 5 additions & 3 deletions server/src/services/typescriptService/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
} from './transformTemplate';
import { templateSourceMap } from './serviceHost';
import { generateSourceMap } from './sourceMap';
import { isVirtualVueTemplateFile, isVueFile } from './util';
import { isVirtualVueTemplateFile } from './util';
import { ChildComponent } from '../vueInfoService';
import { kebabCase, snakeCase } from 'lodash';
import { RuntimeLibrary } from '../dependencyService';
import { EnvironmentService } from '../EnvironmentService';

const importedComponentName = '__vlsComponent';

Expand Down Expand Up @@ -52,7 +53,8 @@ export function parseVueTemplate(text: string): string {

export function createUpdater(
tsModule: RuntimeLibrary['typescript'],
allChildComponentsInfo: Map<string, ChildComponent[]>
allChildComponentsInfo: Map<string, ChildComponent[]>,
env: EnvironmentService
) {
const clssf = tsModule.createLanguageServiceSourceFile;
const ulssf = tsModule.updateLanguageServiceSourceFile;
Expand All @@ -71,7 +73,7 @@ export function createUpdater(
return;
}

if (isVueFile(fileName)) {
if (env.isVueFile(fileName)) {
modifyVueScript(tsModule, sourceFile);
modificationTracker.add(sourceFile);
return;
Expand Down
15 changes: 8 additions & 7 deletions server/src/services/typescriptService/serviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getFileFsPath, getFilePath, normalizeFileNameToFsPath } from '../../uti
import * as bridge from './bridge';
import { getVueSys } from './vueSys';
import { TemplateSourceMap, stringifySourceMapNodes } from './sourceMap';
import { isVirtualVueTemplateFile, isVueFile } from './util';
import { isVirtualVueTemplateFile } from './util';
import { logger } from '../../log';
import { ModuleResolutionCache } from './moduleResolutionCache';
import { globalScope } from './transformTemplate';
Expand All @@ -25,12 +25,13 @@ const NEWLINE = process.platform === 'win32' ? '\r\n' : '\n';
*/
const allChildComponentsInfo = new Map<string, ChildComponent[]>();

function patchTS(tsModule: RuntimeLibrary['typescript']) {
function patchTS(tsModule: RuntimeLibrary['typescript'], env: EnvironmentService) {
// Patch typescript functions to insert `import Vue from 'vue'` and `new Vue` around export default.
// NOTE: this is a global hack that all ts instances after is changed
const { createLanguageServiceSourceFile, updateLanguageServiceSourceFile } = createUpdater(
tsModule,
allChildComponentsInfo
allChildComponentsInfo,
env
);
(tsModule as any).createLanguageServiceSourceFile = createLanguageServiceSourceFile;
(tsModule as any).updateLanguageServiceSourceFile = updateLanguageServiceSourceFile;
Expand Down Expand Up @@ -89,7 +90,7 @@ export function getServiceHost(
env: EnvironmentService,
updatedScriptRegionDocuments: LanguageModelCache<TextDocument>
): IServiceHost {
patchTS(tsModule);
patchTS(tsModule, env);

let currentScriptDoc: TextDocument;

Expand Down Expand Up @@ -298,7 +299,7 @@ export function getServiceHost(
return (tsModule as any).getScriptKindFromFileName(fileName);
}

if (isVueFile(fileName)) {
if (env.isVueFile(fileName)) {
const uri = URI.file(fileName);
const fileFsPath = normalizeFileNameToFsPath(fileName);
let doc = localScriptRegionDocuments.get(fileFsPath);
Expand Down Expand Up @@ -354,7 +355,7 @@ export function getServiceHost(
return cachedResolvedModule;
}

if (!isVueFile(name)) {
if (!env.isVueFile(name)) {
const tsResolvedModule = tsModule.resolveModuleName(name, containingFile, options, tsModule.sys)
.resolvedModule;

Expand Down Expand Up @@ -446,7 +447,7 @@ export function getServiceHost(
}

// js/ts files in workspace
if (!isVueFile(fileFsPath)) {
if (!env.isVueFile(fileFsPath)) {
if (projectFileSnapshots.has(fileFsPath)) {
return projectFileSnapshots.get(fileFsPath);
}
Expand Down
4 changes: 0 additions & 4 deletions server/src/services/typescriptService/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type ts from 'typescript';
import { CompletionItemKind, SymbolKind } from 'vscode-languageserver';

export function isVueFile(path: string) {
return path.endsWith('.vue');
}

/**
* If the path ends with `.vue.ts`, it's a `.vue` file pre-processed by Vetur
* to be used in TS Language Service
Expand Down
3 changes: 2 additions & 1 deletion vti/src/initParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function getDefaultVLSConfig() {
},
experimental: {
templateInterpolationService: false
}
},
extentions: []
},
css: {},
html: {
Expand Down