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

Allows plugin to register commands #44291

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ namespace ts.server {
/** @deprecated use serverMode instead */
syntaxOnly?: boolean;
serverMode?: LanguageServiceMode;
session: Session<unknown> | undefined;
Kingwl marked this conversation as resolved.
Show resolved Hide resolved
}

interface OriginalFileInfo { fileName: NormalizedPath; path: Path; }
Expand Down Expand Up @@ -782,6 +783,7 @@ namespace ts.server {
readonly packageJsonCache: PackageJsonCache;
/*@internal*/
private packageJsonFilesMap: ESMap<Path, FileWatcher> | undefined;
private session: Session<unknown> | undefined;
Kingwl marked this conversation as resolved.
Show resolved Hide resolved


private performanceEventHandler?: PerformanceEventHandler;
Expand All @@ -800,6 +802,8 @@ namespace ts.server {
this.pluginProbeLocations = opts.pluginProbeLocations || emptyArray;
this.allowLocalPluginLoads = !!opts.allowLocalPluginLoads;
this.typesMapLocation = (opts.typesMapLocation === undefined) ? combinePaths(getDirectoryPath(this.getExecutingFilePath()), "typesMap.json") : opts.typesMapLocation;
this.session = opts.session;

if (opts.serverMode !== undefined) {
this.serverMode = opts.serverMode;
this.syntaxOnly = this.serverMode === LanguageServiceMode.Syntactic;
Expand Down Expand Up @@ -2068,7 +2072,8 @@ namespace ts.server {
canonicalConfigFilePath,
this,
this.documentRegistry,
configFileExistenceInfo.config.cachedDirectoryStructureHost);
configFileExistenceInfo.config.cachedDirectoryStructureHost,
this.session);
Kingwl marked this conversation as resolved.
Show resolved Hide resolved
this.configuredProjects.set(canonicalConfigFilePath, project);
this.createConfigFileWatcherForParsedConfig(configFileName, canonicalConfigFilePath, project);
return project;
Expand Down Expand Up @@ -2517,7 +2522,7 @@ namespace ts.server {
typeAcquisition = this.typeAcquisitionForInferredProjects;
}
watchOptionsAndErrors = watchOptionsAndErrors || undefined;
const project = new InferredProject(this, this.documentRegistry, compilerOptions, watchOptionsAndErrors?.watchOptions, projectRootPath, currentDirectory, this.currentPluginConfigOverrides, typeAcquisition);
const project = new InferredProject(this, this.documentRegistry, compilerOptions, watchOptionsAndErrors?.watchOptions, projectRootPath, currentDirectory, this.currentPluginConfigOverrides, typeAcquisition, this.session);
project.setProjectErrors(watchOptionsAndErrors?.errors);
if (isSingleInferredProject) {
this.inferredProjects.unshift(project);
Expand Down
27 changes: 20 additions & 7 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace ts.server {
languageService: LanguageService;
languageServiceHost: LanguageServiceHost;
serverHost: ServerHost;
session?: Session<unknown>;
config: any;
}

Expand Down Expand Up @@ -262,6 +263,8 @@ namespace ts.server {
/*@internal*/
protected typeAcquisition: TypeAcquisition | undefined;

private session: Session<unknown> | undefined;

/*@internal*/
constructor(
/*@internal*/ readonly projectName: string,
Expand All @@ -275,10 +278,12 @@ namespace ts.server {
protected watchOptions: WatchOptions | undefined,
directoryStructureHost: DirectoryStructureHost,
currentDirectory: string | undefined,
session: Session<unknown> | undefined,
) {
this.directoryStructureHost = directoryStructureHost;
this.currentDirectory = this.projectService.getNormalizedAbsolutePath(currentDirectory || "");
this.getCanonicalFileName = this.projectService.toCanonicalFileName;
this.session = session;

this.cancellationToken = new ThrottledCancellationToken(this.projectService.cancellationToken, this.projectService.throttleWaitMilliseconds);
if (!this.compilerOptions) {
Expand Down Expand Up @@ -1603,7 +1608,8 @@ namespace ts.server {
project: this,
languageService: this.languageService,
languageServiceHost: this,
serverHost: this.projectService.host
serverHost: this.projectService.host,
session: this.session
};

const pluginModule = pluginModuleFactory({ typescript: ts });
Expand Down Expand Up @@ -1806,7 +1812,8 @@ namespace ts.server {
projectRootPath: NormalizedPath | undefined,
currentDirectory: string | undefined,
pluginConfigOverrides: ESMap<string, any> | undefined,
typeAcquisition: TypeAcquisition | undefined) {
typeAcquisition: TypeAcquisition | undefined,
session: Session<unknown> | undefined) {
super(InferredProject.newName(),
ProjectKind.Inferred,
projectService,
Expand All @@ -1818,7 +1825,8 @@ namespace ts.server {
/*compileOnSaveEnabled*/ false,
watchOptions,
projectService.host,
currentDirectory);
currentDirectory,
session);
this.typeAcquisition = typeAcquisition;
this.projectRootPath = projectRootPath && projectService.toCanonicalFileName(projectRootPath);
if (!projectRootPath && !projectService.useSingleInferredProject) {
Expand Down Expand Up @@ -1971,7 +1979,8 @@ namespace ts.server {
/*compileOnSaveEnabled*/ false,
hostProject.getWatchOptions(),
hostProject.projectService.host,
hostProject.currentDirectory);
hostProject.currentDirectory,
/*session*/ undefined);

this.rootFileNames = initialRootNames;
this.useSourceOfProjectReferenceRedirect = maybeBind(this.hostProject, this.hostProject.useSourceOfProjectReferenceRedirect);
Expand Down Expand Up @@ -2100,7 +2109,8 @@ namespace ts.server {
readonly canonicalConfigFilePath: NormalizedPath,
projectService: ProjectService,
documentRegistry: DocumentRegistry,
cachedDirectoryStructureHost: CachedDirectoryStructureHost) {
cachedDirectoryStructureHost: CachedDirectoryStructureHost,
session: Session<unknown> | undefined) {
super(configFileName,
ProjectKind.Configured,
projectService,
Expand All @@ -2112,6 +2122,7 @@ namespace ts.server {
/*watchOptions*/ undefined,
cachedDirectoryStructureHost,
getDirectoryPath(configFileName),
session
);
}

Expand Down Expand Up @@ -2380,7 +2391,8 @@ namespace ts.server {
public compileOnSaveEnabled: boolean,
projectFilePath?: string,
pluginConfigOverrides?: ESMap<string, any>,
watchOptions?: WatchOptions) {
watchOptions?: WatchOptions,
session?: Session<unknown>) {
super(externalProjectName,
ProjectKind.External,
projectService,
Expand All @@ -2391,7 +2403,8 @@ namespace ts.server {
compileOnSaveEnabled,
watchOptions,
projectService.host,
getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName)));
getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName)),
session);
this.enableGlobalPlugins(this.getCompilerOptions(), pluginConfigOverrides);
}

Expand Down
1 change: 1 addition & 0 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ namespace ts.server {
typesMapLocation: opts.typesMapLocation,
syntaxOnly: opts.syntaxOnly,
serverMode: opts.serverMode,
session: this
};
this.projectService = new ProjectService(settings);
this.projectService.setPerformanceEventHandler(this.performanceEventHandler.bind(this));
Expand Down