-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Support services settings #22236
Conversation
b47c0f3
to
a40fab8
Compare
FYI @RyanCavanaugh |
src/services/types.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/server/protocol.ts
Outdated
@@ -1232,6 +1232,8 @@ namespace ts.server.protocol { | |||
*/ | |||
formatOptions?: FormatCodeSettings; | |||
|
|||
servicesOptions?: ServicesSettings; |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah.
src/server/session.ts
Outdated
@@ -2151,6 +2150,14 @@ namespace ts.server { | |||
"Error processing request. " + (<StackTraceError>err).message + "\n" + (<StackTraceError>err).stack); | |||
} | |||
} | |||
|
|||
private formatSettings(file: NormalizedPath): FormatCodeSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getFormatOptions
?
src/server/protocol.ts
Outdated
@@ -2588,6 +2590,10 @@ namespace ts.server.protocol { | |||
insertSpaceBeforeTypeAnnotation?: boolean; | |||
} | |||
|
|||
export interface ServicesSettings { | |||
quote: '"' | "'"; |
There was a problem hiding this comment.
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.
We also need this in the importfixes file, do you plan on doing this in a separate PR or in this PR? |
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. |
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)? |
src/server/editorServices.ts
Outdated
@@ -200,6 +200,7 @@ namespace ts.server { | |||
|
|||
export interface HostConfiguration { | |||
formatCodeOptions: FormatCodeSettings; | |||
servicesOptions: ServicesSettings; |
There was a problem hiding this comment.
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"?
src/services/types.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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
?
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. |
src/server/protocol.ts
Outdated
@@ -2588,6 +2588,20 @@ namespace ts.server.protocol { | |||
insertSpaceBeforeTypeAnnotation?: boolean; | |||
} | |||
|
|||
export interface Options { | |||
quote: "double" | "single"; |
There was a problem hiding this comment.
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.
src/server/protocol.ts
Outdated
*/ | ||
includeExternalModuleExports: boolean; | ||
includeExternalModuleExports?: boolean; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
src/services/services.ts
Outdated
}); | ||
} | ||
|
||
function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions { | ||
function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, options: Options): CombinedCodeActions { |
There was a problem hiding this comment.
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
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>; |
There was a problem hiding this comment.
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?
…todo: come up with better names)
src/services/types.ts
Outdated
@@ -214,6 +214,14 @@ namespace ts { | |||
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>; | |||
} | |||
|
|||
export interface Options { |
There was a problem hiding this comment.
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
src/services/types.ts
Outdated
@@ -214,6 +214,14 @@ namespace ts { | |||
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>; | |||
} | |||
|
|||
export interface Options { | |||
readonly quote?: "double" | "single"; | |||
readonly includeCompletionsForExternalModuleExports?: boolean; |
There was a problem hiding this comment.
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"
src/services/types.ts
Outdated
export interface Options { | ||
readonly quote?: "double" | "single"; | ||
readonly includeCompletionsForExternalModuleExports?: boolean; | ||
readonly includeCompletionsWithInsertText?: boolean; |
There was a problem hiding this comment.
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.
tests/cases/fourslash/fourslash.ts
Outdated
@@ -527,6 +522,13 @@ declare namespace FourSlashInterface { | |||
category: string; | |||
code: number; | |||
} | |||
interface Options { | |||
quote?: "double" | "single"; | |||
includeInsertTextCompletions?: boolean; |
There was a problem hiding this comment.
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?
1463a6a
to
b218afe
Compare
b218afe
to
c0e2d52
Compare
beb6aef
to
ce9ddde
Compare
6525eb1
to
468d900
Compare
468d900
to
ca0beaf
Compare
src/server/protocol.ts
Outdated
*/ | ||
includeInsertTextCompletions: boolean; | ||
includeInsertTextCompletions?: boolean; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
src/server/protocol.ts
Outdated
* 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"; |
There was a problem hiding this comment.
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
src/server/protocol.ts
Outdated
@@ -2633,6 +2633,21 @@ namespace ts.server.protocol { | |||
insertSpaceBeforeTypeAnnotation?: boolean; | |||
} | |||
|
|||
export interface Options { | |||
readonly quote?: "double" | "single"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotePreference
src/server/protocol.ts
Outdated
@@ -2633,6 +2633,21 @@ namespace ts.server.protocol { | |||
insertSpaceBeforeTypeAnnotation?: boolean; | |||
} | |||
|
|||
export interface Options { |
There was a problem hiding this comment.
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)
f0d972c
to
d48a7d7
Compare
d48a7d7
to
6e1adaf
Compare
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" |
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 otherLanguageService
methods eventually.