Skip to content

Commit

Permalink
Refactor to autoImportSfcPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Nov 26, 2020
1 parent b22bbe6 commit 2ea0666
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions server/src/embeddedSupport/languageModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { BasicComponentInfo, VLSFullConfig } from '../config';
import { SassLanguageMode } from '../modes/style/sass/sassLanguageMode';
import { getPugMode } from '../modes/pug';
import { VCancellationToken } from '../utils/cancellationToken';
import { createAutoImportVueService } from '../services/autoImportVueService';
import { createAutoImportSfcPlugin } from '../modes/plugins/autoImportSfcPlugin';

export interface VLSServices {
dependencyService: DependencyService;
Expand Down Expand Up @@ -130,9 +130,9 @@ export class LanguageModes {
return vueDocument.getSingleTypeDocument('script');
});
this.serviceHost = getServiceHost(tsModule, projectPath, tsconfigPath, packagePath, scriptRegionDocuments);
const autoImportVueService = createAutoImportVueService(tsModule, services.infoService);
autoImportVueService.setGetTSScriptTarget(() => this.serviceHost.getComplierOptions().target);
autoImportVueService.setGetFilesFn(() =>
const autoImportSfcPlugin = createAutoImportSfcPlugin(tsModule, services.infoService);
autoImportSfcPlugin.setGetTSScriptTarget(() => this.serviceHost.getComplierOptions().target);
autoImportSfcPlugin.setGetFilesFn(() =>
this.serviceHost.getFileNames().filter(fileName => fileName.endsWith('.vue'))
);

Expand All @@ -142,7 +142,7 @@ export class LanguageModes {
this.documentRegions,
projectPath,
packagePath,
autoImportVueService,
autoImportSfcPlugin,
services.dependencyService,
services.infoService
);
Expand All @@ -154,7 +154,7 @@ export class LanguageModes {
globalComponentInfos,
services.infoService
);
autoImportVueService.setGetJSResolve(jsMode.doResolve!);
autoImportSfcPlugin.setGetJSResolve(jsMode.doResolve!);

this.modes['vue'] = getVueMode(snippetFolder, globalSnippetDir);
this.modes['vue-html'] = vueHtmlMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type ts from 'typescript';
import { CompletionItem } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { TextEdit } from 'vscode-languageserver-types';
import { VLSFullConfig } from '../config';
import { modulePathToValidIdentifier, toMarkupContent } from '../utils/strings';
import { RuntimeLibrary } from './dependencyService';
import { ChildComponent, VueInfoService } from './vueInfoService';
import { VLSFullConfig } from '../../config';
import { modulePathToValidIdentifier, toMarkupContent } from '../../utils/strings';
import { RuntimeLibrary } from '../../services/dependencyService';
import { ChildComponent, VueInfoService } from '../../services/vueInfoService';

export interface AutoImportVueService {
export interface AutoImportSfcPlugin {
setGetConfigure(fn: () => VLSFullConfig): void;
setGetFilesFn(fn: () => string[]): void;
setGetJSResolve(fn: (doc: TextDocument, item: CompletionItem) => CompletionItem): void;
Expand Down Expand Up @@ -41,10 +41,10 @@ export interface AutoImportVueService {
* }
* ```
*/
export function createAutoImportVueService(
export function createAutoImportSfcPlugin(
tsModule: RuntimeLibrary['typescript'],
vueInfoService?: VueInfoService
): AutoImportVueService {
): AutoImportSfcPlugin {
let getConfigure: () => VLSFullConfig;
let getVueFiles: () => string[];
let getJSResolve: (doc: TextDocument, item: CompletionItem) => CompletionItem;
Expand Down
8 changes: 4 additions & 4 deletions server/src/modes/template/htmlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { doPropValidation } from './services/vuePropValidation';
import { getFoldingRanges } from './services/htmlFolding';
import { DependencyService } from '../../services/dependencyService';
import { isVCancellationRequested, VCancellationToken } from '../../utils/cancellationToken';
import { AutoImportVueService } from '../../services/autoImportVueService';
import { AutoImportSfcPlugin } from '../plugins/autoImportSfcPlugin';

export class HTMLMode implements LanguageMode {
private tagProviderSettings: CompletionConfiguration;
Expand All @@ -47,7 +47,7 @@ export class HTMLMode implements LanguageMode {
vueVersion: VueVersion,
private dependencyService: DependencyService,
private vueDocuments: LanguageModelCache<HTMLDocument>,
private autoImportVueService: AutoImportVueService,
private autoImportSfcPlugin: AutoImportSfcPlugin,
private vueInfoService?: VueInfoService
) {
this.tagProviderSettings = getTagProviderSettings(projectPath, packagePath);
Expand All @@ -65,7 +65,7 @@ export class HTMLMode implements LanguageMode {
configure(c: VLSFullConfig) {
this.enabledTagProviders = getEnabledTagProviders(this.tagProviderSettings);
this.config = c;
this.autoImportVueService.setGetConfigure(() => c);
this.autoImportSfcPlugin.setGetConfigure(() => c);
}

async doValidation(document: TextDocument, cancellationToken?: VCancellationToken) {
Expand Down Expand Up @@ -106,7 +106,7 @@ export class HTMLMode implements LanguageMode {
this.vueDocuments.refreshAndGet(embedded),
tagProviders,
this.config.emmet,
this.autoImportVueService.doComplete(document)
this.autoImportSfcPlugin.doComplete(document)
);
}
doHover(document: TextDocument, position: Position) {
Expand Down
14 changes: 7 additions & 7 deletions server/src/modes/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import { HTMLDocument, parseHTMLDocument } from './parser/htmlParser';
import { inferVueVersion } from '../../services/typescriptService/vueVersion';
import { DependencyService, RuntimeLibrary } from '../../services/dependencyService';
import { VCancellationToken } from '../../utils/cancellationToken';
import { AutoImportVueService } from '../../services/autoImportVueService';
import { AutoImportSfcPlugin } from '../plugins/autoImportSfcPlugin';

type DocumentRegionCache = LanguageModelCache<VueDocumentRegions>;

export class VueHTMLMode implements LanguageMode {
private htmlMode: HTMLMode;
private vueInterpolationMode: VueInterpolationMode;
private autoImportVueService: AutoImportVueService;
private autoImportSfcPlugin: AutoImportSfcPlugin;

constructor(
tsModule: RuntimeLibrary['typescript'],
serviceHost: IServiceHost,
documentRegions: DocumentRegionCache,
projectPath: string,
packagePath: string | undefined,
autoImportVueService: AutoImportVueService,
autoImportSfcPlugin: AutoImportSfcPlugin,
dependencyService: DependencyService,
vueInfoService?: VueInfoService
) {
Expand All @@ -40,11 +40,11 @@ export class VueHTMLMode implements LanguageMode {
vueVersion,
dependencyService,
vueDocuments,
autoImportVueService,
autoImportSfcPlugin,
vueInfoService
);
this.vueInterpolationMode = new VueInterpolationMode(tsModule, serviceHost, vueDocuments, vueInfoService);
this.autoImportVueService = autoImportVueService;
this.autoImportSfcPlugin = autoImportSfcPlugin;
}
getId() {
return 'vue-html';
Expand All @@ -71,8 +71,8 @@ export class VueHTMLMode implements LanguageMode {
};
}
doResolve(document: TextDocument, item: CompletionItem): CompletionItem {
if (this.autoImportVueService.isMyResolve(item)) {
return this.autoImportVueService.doResolve(document, item);
if (this.autoImportSfcPlugin.isMyResolve(item)) {
return this.autoImportSfcPlugin.doResolve(document, item);
}
return this.vueInterpolationMode.doResolve(document, item);
}
Expand Down

0 comments on commit 2ea0666

Please sign in to comment.