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 'disableSuggestions' to UserPreferences #23283

Merged
5 commits merged into from
Apr 10, 2018
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
53 changes: 52 additions & 1 deletion src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4131,7 +4131,7 @@ namespace ts.projectSystem {
checkErrorMessage(session, "semanticDiag", { file: file1.path, diagnostics: [] });
});

it("info diagnostics", () => {
it("suggestion diagnostics", () => {
const file: FileOrFolder = {
path: "/a.js",
content: 'require("b")',
Expand Down Expand Up @@ -4184,6 +4184,57 @@ namespace ts.projectSystem {
session.clearMessages();
});

it("disable suggestion diagnostics", () => {
const file: FileOrFolder = {
path: "/a.js",
content: 'require("b")',
};

const host = createServerHost([file]);
const session = createSession(host, { canUseEvents: true });
const service = session.getProjectService();

session.executeCommandSeq<protocol.OpenRequest>({
command: server.CommandNames.Open,
arguments: { file: file.path, fileContent: file.content },
});

session.executeCommandSeq<protocol.ConfigureRequest>({
command: server.CommandNames.Configure,
arguments: {
preferences: { disableSuggestions: true }
},
});

checkNumberOfProjects(service, { inferredProjects: 1 });
session.clearMessages();
const expectedSequenceId = session.getNextSeq();
host.checkTimeoutQueueLengthAndRun(2);

checkProjectUpdatedInBackgroundEvent(session, [file.path]);
session.clearMessages();

session.executeCommandSeq<protocol.GeterrRequest>({
command: server.CommandNames.Geterr,
arguments: {
delay: 0,
files: [file.path],
}
});

host.checkTimeoutQueueLengthAndRun(1);

checkErrorMessage(session, "syntaxDiag", { file: file.path, diagnostics: [] }, /*isMostRecent*/ true);
session.clearMessages();

host.runQueuedImmediateCallbacks(1);

checkErrorMessage(session, "semanticDiag", { file: file.path, diagnostics: [] });
// No suggestion event, we're done.
checkCompleteEvent(session, 2, expectedSequenceId);
session.clearMessages();
});

it("suppressed diagnostic events", () => {
const file: FileOrFolder = {
path: "/a.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,11 +1842,11 @@ namespace ts.server {
this.logger.info(`Host information ${args.hostInfo}`);
}
if (args.formatOptions) {
mergeMapLikes(this.hostConfiguration.formatCodeOptions, convertFormatOptions(args.formatOptions));
this.hostConfiguration.formatCodeOptions = mergeMapLikes(this.hostConfiguration.formatCodeOptions, convertFormatOptions(args.formatOptions));
this.logger.info("Format host information updated");
}
if (args.preferences) {
mergeMapLikes(this.hostConfiguration.preferences, args.preferences);
this.hostConfiguration.preferences = mergeMapLikes(this.hostConfiguration.preferences, args.preferences);
}
if (args.extraFileExtensions) {
this.hostConfiguration.extraFileExtensions = args.extraFileExtensions;
Expand Down
1 change: 1 addition & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ namespace ts.server.protocol {
}

export interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
/**
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
Expand Down
6 changes: 3 additions & 3 deletions src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@ namespace ts.server {
if (!this.formatSettings) {
this.formatSettings = getDefaultFormatCodeSettings(this.host);
Copy link
Member

Choose a reason for hiding this comment

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

This function returns a copy, so it is ok to modify .. So no need to clone unlike defaultPreferences... I am not sure how many times we call these configure function to say if its ok to clone the object (esp with such a big set of properties)

Copy link
Author

Choose a reason for hiding this comment

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

Done.

}
mergeMapLikes(this.formatSettings, formatSettings);
this.formatSettings = mergeMapLikes(this.formatSettings, formatSettings);
}

if (preferences) {
if (!this.preferences) {
this.preferences = clone(defaultPreferences);
this.preferences = defaultPreferences;
}
mergeMapLikes(this.preferences, preferences);
this.preferences = mergeMapLikes(this.preferences, preferences);
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,20 @@ namespace ts.server {
return;
}

next.immediate(() => {
this.suggestionCheck(fileName, project);
const goNext = () => {
if (checkList.length > index) {
next.delay(followMs, checkOne);
}
});
};
if (this.getPreferences(fileName).disableSuggestions) {
goNext();
}
else {
next.immediate(() => {
this.suggestionCheck(fileName, project);
goNext();
});
}
});
};

Expand Down
7 changes: 5 additions & 2 deletions src/server/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ namespace ts.server {
};
}

export function mergeMapLikes<T extends object>(target: T, source: Partial<T>): void {
/* @internal */
export function mergeMapLikes<T extends object>(target: T, source: Partial<T>): T {
const result = clone(target);
for (const key in source) {
if (hasProperty(source, key)) {
target[key] = source[key];
result[key] = source[key];
}
}
return result;
}

export type NormalizedPath = string & { __normalizedPathTag: any };
Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ namespace ts {
}

export interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,7 @@ declare namespace ts {
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
Expand Down Expand Up @@ -5041,7 +5042,6 @@ declare namespace ts.server {
function ThrowProjectDoesNotContainDocument(fileName: string, project: Project): never;
}
function getDefaultFormatCodeSettings(host: ServerHost): FormatCodeSettings;
function mergeMapLikes<T extends object>(target: T, source: Partial<T>): void;
type NormalizedPath = string & {
__normalizedPathTag: any;
};
Expand Down Expand Up @@ -7156,6 +7156,7 @@ declare namespace ts.server.protocol {
insertSpaceBeforeTypeAnnotation?: boolean;
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
/**
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4369,6 +4369,7 @@ declare namespace ts {
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
Expand Down