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 5 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
10 changes: 8 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ namespace ts.server {
config?: ParsedConfig;
}

export interface ProjectServiceOptions {
export interface ProjectServiceOptions<TMessage = string> {
host: ServerHost;
logger: Logger;
cancellationToken: HostCancellationToken;
Expand All @@ -411,6 +411,7 @@ namespace ts.server {
/** @deprecated use serverMode instead */
syntaxOnly?: boolean;
serverMode?: LanguageServiceMode;
session: Session<TMessage> | undefined;
}

interface OriginalFileInfo { fileName: NormalizedPath; path: Path; }
Expand Down Expand Up @@ -783,10 +784,13 @@ namespace ts.server {
/*@internal*/
private packageJsonFilesMap: ESMap<Path, FileWatcher> | undefined;

/*@internal*/
readonly session: Session<unknown> | undefined;
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 you should wire TMessage thing here and PluginCreateInfo too,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the unknown is better:

If we add type parameter TMessage into editorService, We should also add the type parameter into Project and etc. Too many changes.

And we are not really care about the type of message in editorService. We just forward session into pluin.

And the handlers or addProtocolHandler does not have TMessage too. Thay are raw string.

Copy link
Member

Choose a reason for hiding this comment

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

If that’s the case we shouldn’t add it to project service options either

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.



private performanceEventHandler?: PerformanceEventHandler;

constructor(opts: ProjectServiceOptions) {
constructor(opts: ProjectServiceOptions<unknown>) {
this.host = opts.host;
this.logger = opts.logger;
this.cancellationToken = opts.cancellationToken;
Expand All @@ -800,6 +804,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
6 changes: 4 additions & 2 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 @@ -1603,7 +1604,8 @@ namespace ts.server {
project: this,
languageService: this.languageService,
languageServiceHost: this,
serverHost: this.projectService.host
serverHost: this.projectService.host,
session: this.projectService.session
};

const pluginModule = pluginModuleFactory({ typescript: ts });
Expand Down Expand Up @@ -2111,7 +2113,7 @@ namespace ts.server {
/*compileOnSaveEnabled*/ false,
/*watchOptions*/ undefined,
cachedDirectoryStructureHost,
getDirectoryPath(configFileName),
getDirectoryPath(configFileName)
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ namespace ts.server {
isCancellationRequested: () => this.cancellationToken.isCancellationRequested()
};
this.errorCheck = new MultistepOperation(multistepOperationHost);
const settings: ProjectServiceOptions = {
const settings: ProjectServiceOptions<TMessage> = {
host: this.host,
logger: this.logger,
cancellationToken: this.cancellationToken,
Expand All @@ -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
1 change: 1 addition & 0 deletions src/testRunner/unittests/tsserver/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ namespace ts.projectSystem {
super({
host,
logger,
session: undefined,
cancellationToken,
useSingleInferredProject,
useInferredProjectPerProjectRoot: false,
Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9554,6 +9554,7 @@ declare namespace ts.server {
languageService: LanguageService;
languageServiceHost: LanguageServiceHost;
serverHost: ServerHost;
session?: Session<unknown>;
config: any;
}
interface PluginModule {
Expand Down Expand Up @@ -9930,7 +9931,7 @@ declare namespace ts.server {
configFileName?: NormalizedPath;
configFileErrors?: readonly Diagnostic[];
}
export interface ProjectServiceOptions {
export interface ProjectServiceOptions<TMessage = string> {
host: ServerHost;
logger: Logger;
cancellationToken: HostCancellationToken;
Expand All @@ -9947,6 +9948,7 @@ declare namespace ts.server {
/** @deprecated use serverMode instead */
syntaxOnly?: boolean;
serverMode?: LanguageServiceMode;
session: Session<TMessage> | undefined;
}
export interface WatchOptionsAndErrors {
watchOptions: WatchOptions;
Expand Down Expand Up @@ -10022,7 +10024,7 @@ declare namespace ts.server {
/** Tracks projects that we have already sent telemetry for. */
private readonly seenProjects;
private performanceEventHandler?;
constructor(opts: ProjectServiceOptions);
constructor(opts: ProjectServiceOptions<unknown>);
toPath(fileName: string): Path;
private loadTypesMap;
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void;
Expand Down