mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add 'disableSuggestions' to UserPreferences (#23283)
* Add 'disableSuggestions' to UserPreferences * Make mergeMapLikes return a new object * Avoid additional clone * mergeMapLikes -> object spread
This commit is contained in:
@@ -1268,10 +1268,7 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
export function assign<T1 extends MapLike<{}>, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3;
|
||||
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
|
||||
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
|
||||
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]) {
|
||||
export function assign<T extends object>(t: T, ...args: T[]) {
|
||||
for (const arg of args) {
|
||||
for (const p in arg) {
|
||||
if (hasProperty(arg, p)) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 = { ...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 = { ...this.hostConfiguration.preferences, ...args.preferences };
|
||||
}
|
||||
if (args.extraFileExtensions) {
|
||||
this.hostConfiguration.extraFileExtensions = args.extraFileExtensions;
|
||||
|
||||
@@ -2640,6 +2640,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.
|
||||
|
||||
@@ -397,15 +397,18 @@ namespace ts.server {
|
||||
if (formatSettings) {
|
||||
if (!this.formatSettings) {
|
||||
this.formatSettings = getDefaultFormatCodeSettings(this.host);
|
||||
assign(this.formatSettings, formatSettings);
|
||||
}
|
||||
else {
|
||||
this.formatSettings = { ...this.formatSettings, ...formatSettings };
|
||||
}
|
||||
mergeMapLikes(this.formatSettings, formatSettings);
|
||||
}
|
||||
|
||||
if (preferences) {
|
||||
if (!this.preferences) {
|
||||
this.preferences = clone(defaultPreferences);
|
||||
this.preferences = defaultPreferences;
|
||||
}
|
||||
mergeMapLikes(this.preferences, preferences);
|
||||
this.preferences = { ...this.preferences, ...preferences };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -528,12 +528,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();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -83,14 +83,6 @@ namespace ts.server {
|
||||
};
|
||||
}
|
||||
|
||||
export function mergeMapLikes<T extends object>(target: T, source: Partial<T>): void {
|
||||
for (const key in source) {
|
||||
if (hasProperty(source, key)) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type NormalizedPath = string & { __normalizedPathTag: any };
|
||||
|
||||
export function toNormalizedPath(fileName: string): NormalizedPath {
|
||||
|
||||
@@ -228,6 +228,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface UserPreferences {
|
||||
readonly disableSuggestions?: boolean;
|
||||
readonly quotePreference?: "double" | "single";
|
||||
readonly includeCompletionsForModuleExports?: boolean;
|
||||
readonly includeCompletionsWithInsertText?: boolean;
|
||||
|
||||
+2
-1
@@ -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;
|
||||
@@ -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;
|
||||
};
|
||||
@@ -7157,6 +7157,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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user