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

Support services settings #22236

Merged
13 commits merged into from
Mar 20, 2018
Merged

Support services settings #22236

13 commits merged into from
Mar 20, 2018

Conversation

ghost
Copy link

@ghost ghost commented Feb 28, 2018

Start of #20619
Fixes #22342
Fixes #22249
Fixes #18169

This expands the "configure" request to include a second set of settings. It also adds the settings as a new parameter to getCompletionsAtPosition; we'll probably want to add it to many other LanguageService methods eventually.

@ghost ghost requested review from mhegazy, sheetalkamat and amcasey February 28, 2018 19:14
@amcasey
Copy link
Member

amcasey commented Mar 1, 2018

FYI @RyanCavanaugh

@@ -242,7 +250,7 @@ namespace ts {
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications;

getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo;
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined, settings: ServicesSettings | undefined): CompletionInfo;
Copy link
Member

Choose a reason for hiding this comment

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

make it optional instead so that the api doesn't break

Copy link
Author

@ghost ghost Mar 1, 2018

Choose a reason for hiding this comment

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

Like with the options: GetCompletionsAtPositionOptions | undefined,, this is a types breaking change but will handle it gracefully at runtime -- we want to be reminding people to send us the settings though.

@@ -1232,6 +1232,8 @@ namespace ts.server.protocol {
*/
formatOptions?: FormatCodeSettings;

servicesOptions?: ServicesSettings;
Copy link
Contributor

@mhegazy mhegazy Mar 1, 2018

Choose a reason for hiding this comment

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

consider renaming this to just options. since we intend to make this the bag of all options that are not formatting,

Copy link
Author

Choose a reason for hiding this comment

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

Should the type be Options too?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah.

@@ -2151,6 +2150,14 @@ namespace ts.server {
"Error processing request. " + (<StackTraceError>err).message + "\n" + (<StackTraceError>err).stack);
}
}

private formatSettings(file: NormalizedPath): FormatCodeSettings {
Copy link
Contributor

Choose a reason for hiding this comment

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

getFormatOptions?

@@ -2588,6 +2590,10 @@ namespace ts.server.protocol {
insertSpaceBeforeTypeAnnotation?: boolean;
}

export interface ServicesSettings {
quote: '"' | "'";
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say create an enum for this, or even a literal union type that is not the quote. e.g. "double" | "single". VSCode at the end of the day will put this setting in a json file and having ppl wiring "\"" is not that great.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 1, 2018

We also need this in the importfixes file, do you plan on doing this in a separate PR or in this PR?

@ghost
Copy link
Author

ghost commented Mar 1, 2018

Most services may eventually need these options -- should we just add it to all methods now instead of doing it one-by-one as we need it?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 1, 2018

Most services may eventually need these options -- should we just add it to all methods now instead of doing it one-by-one as we need it?

GotoDef, findAllRefs, rename, sighelp, etc.. will not need it.. we just need it in things that will generate code, namelly completions, quickfixes, and refactoring. Formatting has its own thing.

@amcasey
Copy link
Member

amcasey commented Mar 2, 2018

I'm not sure I understand the high-level goal of this change. It seems like we wanted to add an option to completion but wanted to avoid having to pass it on every call to completion (vs doing it once at the beginning)?

@@ -200,6 +200,7 @@ namespace ts.server {

export interface HostConfiguration {
formatCodeOptions: FormatCodeSettings;
servicesOptions: ServicesSettings;
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a pattern we follow when choosing between "options" and settings"?

@@ -242,7 +250,7 @@ namespace ts {
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications;

getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo;
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined, settings: ServicesSettings | undefined): CompletionInfo;
Copy link
Member

Choose a reason for hiding this comment

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

Are callers likely to want to pass different values for GetCompletionsAtPositionOptions each time they call getCompletionsAtPosition? Is there some way we can incorporate those options into ServicesSettings?

@ghost ghost mentioned this pull request Mar 5, 2018
@ghost ghost force-pushed the services_settings branch from e3aabe0 to f36bcd3 Compare March 5, 2018 21:29
@ghost ghost force-pushed the services_settings branch from f36bcd3 to 590faf0 Compare March 5, 2018 21:43
@mhegazy
Copy link
Contributor

mhegazy commented Mar 6, 2018

I'm not sure I understand the high-level goal of this change. It seems like we wanted to add an option to completion but wanted to avoid having to pass it on every call to completion (vs doing it once at the beginning)?

we want to add options to codeAction creation logic. that would be in completion (with imports), in quick fixes, and refactoring. the common issues are for instance which quote to use for module names.
These options are more like formatting options, they should be provided once at the beginning, or when they change.

@@ -2588,6 +2588,20 @@ namespace ts.server.protocol {
insertSpaceBeforeTypeAnnotation?: boolean;
}

export interface Options {
quote: "double" | "single";
Copy link
Contributor

Choose a reason for hiding this comment

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

these should be all be optional.

*/
includeExternalModuleExports: boolean;
includeExternalModuleExports?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why should these be lumped with the other... i mean we can change to a global config system, but maybe on a separate change, and then we need to discuss that as well with the VSCode folks and with @amcasey

Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke to @amcasey and seems like it will work for him. so i am fine with he change. we probably need to give them more descriptive names.

Copy link
Author

Choose a reason for hiding this comment

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

Wouldn't changing the name be a breaking change though? Although we could deprecate the existing name and add an equivalent one.

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 @mhegazy meant that we should give them more descriptive names in their new location. In their old location, they have to stay as-is for back-compat.

Copy link
Author

Choose a reason for hiding this comment

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

@amcasey Do you have some good suggestions for the new names?

Copy link
Member

Choose a reason for hiding this comment

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

I had envisioned that they would be in a nested object called (e.g.) "completions". However, if that's not idiomatic, incorporating "completions" into the name should be sufficient - e.g. "includeCompletionsForExternalModuleExports".

});
}

function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions {
function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, options: Options): CombinedCodeActions {
Copy link
Contributor

Choose a reason for hiding this comment

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

we aslo need the options for applicablerefactorings and organizeImports

@ghost ghost force-pushed the services_settings branch from eea8288 to 4d592ee Compare March 6, 2018 16:09
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges>;
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, options: Options): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, options: Options): RefactorEditInfo | undefined;
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<FileTextChanges>;
Copy link
Contributor

@mhegazy mhegazy Mar 6, 2018

Choose a reason for hiding this comment

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

the new options parameter should be optional. right?

@ghost ghost force-pushed the services_settings branch from be34eb6 to 327d688 Compare March 6, 2018 21:32
@@ -214,6 +214,14 @@ namespace ts {
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
}

export interface Options {
Copy link
Member

Choose a reason for hiding this comment

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

I'd really prefer a more descriptive name

@@ -214,6 +214,14 @@ namespace ts {
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
}

export interface Options {
readonly quote?: "double" | "single";
readonly includeCompletionsForExternalModuleExports?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

includeCompletionsForModuleExports because nobody after 2015 should ever use the term "external module"

export interface Options {
readonly quote?: "double" | "single";
readonly includeCompletionsForExternalModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a better name here, but I'm not sure what.

@@ -527,6 +522,13 @@ declare namespace FourSlashInterface {
category: string;
code: number;
}
interface Options {
quote?: "double" | "single";
includeInsertTextCompletions?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

where's the other option here?

@ghost ghost force-pushed the services_settings branch from 1463a6a to b218afe Compare March 12, 2018 21:30
@ghost ghost force-pushed the services_settings branch from b218afe to c0e2d52 Compare March 12, 2018 21:31
@ghost ghost force-pushed the services_settings branch 2 times, most recently from beb6aef to ce9ddde Compare March 12, 2018 22:00
@ghost ghost force-pushed the services_settings branch 3 times, most recently from 6525eb1 to 468d900 Compare March 12, 2018 23:24
@ghost ghost force-pushed the services_settings branch from 468d900 to ca0beaf Compare March 13, 2018 16:39
*/
includeInsertTextCompletions: boolean;
includeInsertTextCompletions?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we have two separate names for the same concept (i.e. different thing in protocol vs services)

Copy link
Author

Choose a reason for hiding this comment

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

This is a deprecated property of CompletionsRequestArgs to support the old name, the new name is later on in this file.

* For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`.
*/
readonly includeCompletionsWithInsertText?: boolean;
readonly importModuleSpecifierPreference?: "relative" | "baseUrl";
Copy link
Member

Choose a reason for hiding this comment

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

We should reconsider if we want to call this something like "non-relative" just because most of the time, people are using this with path-mapping; but I think it really depends on the behavior. If we always give completions from the baseUrl (probably undesirable) then we can keep this as baseUrl. But if we already have this, it's probably fine. @mhegazy @sheetalkamat

@@ -2633,6 +2633,21 @@ namespace ts.server.protocol {
insertSpaceBeforeTypeAnnotation?: boolean;
}

export interface Options {
readonly quote?: "double" | "single";
Copy link
Member

Choose a reason for hiding this comment

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

quotePreference

@@ -2633,6 +2633,21 @@ namespace ts.server.protocol {
insertSpaceBeforeTypeAnnotation?: boolean;
}

export interface Options {
Copy link
Member

Choose a reason for hiding this comment

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

UserPreferences? Thoughts @RyanCavanaugh? (keep #22236 (comment) in mind)

@ghost ghost force-pushed the services_settings branch from f0d972c to d48a7d7 Compare March 15, 2018 19:24
@mhegazy
Copy link
Contributor

mhegazy commented May 15, 2018

These are exposed in VSCode settings:

Quote style:

"typescript.preferences.quoteStyle": "double"

or

"typescript.preferences.quoteStyle": "single"

module import relative vs non-relative:

"typescript.preferences.importModuleSpecifier": "relative"

or

"typescript.preferences.importModuleSpecifier": "non-relative"

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants