Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make mergeMapLikes return a new object
  • Loading branch information
Andy Hanson
Andy Hanson committed Apr 9, 2018
commit 49c04b47efe1cd13dbefc9bb6584fd293566f13a
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
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
Copy Markdown
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
Copy Markdown
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
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
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 @@ -4115,6 +4115,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 @@ -5040,7 +5041,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 @@ -7155,6 +7155,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 @@ -4368,6 +4368,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