-
Notifications
You must be signed in to change notification settings - Fork 123
feat(language-service): Support importing the external module's expor… #2173
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
base: main
Are you sure you want to change the base?
Changes from all commits
06f4f92
c3b58b2
c61de8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ export interface SessionOptions { | |||||
logToConsole: boolean; | ||||||
includeAutomaticOptionalChainCompletions: boolean; | ||||||
includeCompletionsWithSnippetText: boolean; | ||||||
includeCompletionsForModuleExports: boolean; | ||||||
forceStrictTemplates: boolean; | ||||||
disableBlockSyntax: boolean; | ||||||
disableLetSyntax: boolean; | ||||||
|
@@ -49,7 +50,7 @@ const EMPTY_RANGE = lsp.Range.create(0, 0, 0, 0); | |||||
const setImmediateP = promisify(setImmediate); | ||||||
|
||||||
const defaultFormatOptions: ts.FormatCodeSettings = {}; | ||||||
const defaultPreferences: ts.UserPreferences = {}; | ||||||
let defaultPreferences: ts.UserPreferences = {}; | ||||||
|
||||||
const htmlLS = getHTMLLanguageService(); | ||||||
|
||||||
|
@@ -70,6 +71,7 @@ export class Session { | |||||
private readonly openFiles = new MruTracker(); | ||||||
private readonly includeAutomaticOptionalChainCompletions: boolean; | ||||||
private readonly includeCompletionsWithSnippetText: boolean; | ||||||
private readonly includeCompletionsForModuleExports: boolean; | ||||||
private snippetSupport: boolean|undefined; | ||||||
private diagnosticsTimeout: NodeJS.Timeout|null = null; | ||||||
private isProjectLoading = false; | ||||||
|
@@ -86,8 +88,13 @@ export class Session { | |||||
this.includeAutomaticOptionalChainCompletions = | ||||||
options.includeAutomaticOptionalChainCompletions; | ||||||
this.includeCompletionsWithSnippetText = options.includeCompletionsWithSnippetText; | ||||||
this.includeCompletionsForModuleExports = options.includeCompletionsForModuleExports; | ||||||
this.logger = options.logger; | ||||||
this.logToConsole = options.logToConsole; | ||||||
defaultPreferences = { | ||||||
...defaultPreferences, | ||||||
includeCompletionsForModuleExports: options.includeCompletionsForModuleExports, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the absence of this option should then be With the above, should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the default value in the
Yes, for the developer who uses the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I think I understand. Though I don’t know about the part about Angular LS “ignoring these configs”. They didn’t exist on the Angular side before and if I understand correctly, they’re still configured separately so they still “ignore” the typescript option, right? Can we actually just use the typescript option instead of adding a matching one of our own where they can differ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the typescript language server implementation have a default value of true or is it always expected to be set by the client? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is why I need to set the “ignoring these configs”, I mean the Angular developer still can set ngLs.getCompletionsAtPosition(path, position, {
includeCompletionsForModuleExports: false, // this doesn't work.
}) Or maybe I don't add this new config for now. Keep it the same as the old behavior, always provide the global component. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
okay, right that makes sense. The option “existed” but wasn’t used. practically speaking though, developers don’t really interact with the language service directly. It all goes through the language server. I don’t know of any integrations that implement their own server or use the language service directly, though there could be some out there. I think we should consider changing the default here to true: https://github.com/angular/angular/blob/8f9d13ef2bd4ddc10c230ddd0019ef21d9887175/packages/language-service/src/completions.ts#L756 This might not match what typescript has for the default, but I think it could be considered a breaking change to the behavior from before the commit. WDYT? I’m still wrapping my head around this so appreciate your patience walking through this with me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The configuration is passed from the TypeScript language server to the language service. If the default value needs to be changed, two functions(getCompletionsAtPosition, getCompletionEntryDetails) must be updated. For example, here needs to be updated too.
If the developers don’t really interact with the language service directly. I think the language service doesn't need to be changed. Make sure no breaking changes are introduced in the language server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, it probably doesn’t need to change if we change the default in the language server instead. |
||||||
}; | ||||||
// Create a connection for the server. The connection uses Node's IPC as a transport. | ||||||
this.connection = lsp.createConnection({ | ||||||
// cancelUndispatched is a "middleware" to handle all cancellation requests. | ||||||
|
@@ -150,6 +157,7 @@ export class Session { | |||||
// We don't want the AutoImportProvider projects to be created. See | ||||||
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#smarter-auto-imports | ||||||
includePackageJsonAutoImports: 'off', | ||||||
includeCompletionsForModuleExports: this.includeCompletionsForModuleExports, | ||||||
}, | ||||||
watchOptions: { | ||||||
// Used as watch options when not specified by user's `tsconfig`. | ||||||
|
@@ -1234,12 +1242,14 @@ export class Session { | |||||
let options: ts.GetCompletionsAtPositionOptions = {}; | ||||||
const includeCompletionsWithSnippetText = | ||||||
this.includeCompletionsWithSnippetText && this.snippetSupport; | ||||||
if (this.includeAutomaticOptionalChainCompletions || includeCompletionsWithSnippetText) { | ||||||
if (this.includeAutomaticOptionalChainCompletions || includeCompletionsWithSnippetText || | ||||||
this.includeCompletionsForModuleExports) { | ||||||
options = { | ||||||
includeAutomaticOptionalChainCompletions: this.includeAutomaticOptionalChainCompletions, | ||||||
includeCompletionsWithSnippetText: includeCompletionsWithSnippetText, | ||||||
includeCompletionsWithInsertText: | ||||||
this.includeAutomaticOptionalChainCompletions || includeCompletionsWithSnippetText, | ||||||
includeCompletionsForModuleExports: this.includeCompletionsForModuleExports, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -1269,8 +1279,8 @@ export class Session { | |||||
|
||||||
const offset = lspPositionToTsPosition(scriptInfo, position); | ||||||
const details = languageService.getCompletionEntryDetails( | ||||||
filePath, offset, item.insertText ?? item.label, undefined, undefined, undefined, | ||||||
undefined); | ||||||
filePath, offset, item.insertText ?? item.label, undefined, undefined, defaultPreferences, | ||||||
data.tsData); | ||||||
if (details === undefined) { | ||||||
return item; | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,24 @@ describe('parseCommandLine', () => { | |
const options = parseCommandLine(['--tsProbeLocations', '/baz,/qux']); | ||
expect(options.tsProbeLocations).toEqual(['/baz', '/qux']); | ||
}); | ||
|
||
it('should parse without "includeCompletionsForModuleExports"', () => { | ||
const options = parseCommandLine(['--tsProbeLocations', '/baz,/qux']); | ||
expect(options.includeCompletionsForModuleExports).toEqual(true); | ||
}); | ||
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test case when the config |
||
|
||
it('should parse with "--includeCompletionsForModuleExports --help"', () => { | ||
const options = parseCommandLine(['--includeCompletionsForModuleExports', '--help']); | ||
expect(options.includeCompletionsForModuleExports).toEqual(true); | ||
}); | ||
|
||
it('should parse with "--includeCompletionsForModuleExports true --help"', () => { | ||
const options = parseCommandLine(['--includeCompletionsForModuleExports', 'true', '--help']); | ||
expect(options.includeCompletionsForModuleExports).toEqual(true); | ||
}); | ||
|
||
it('should parse with "--includeCompletionsForModuleExports false --help"', () => { | ||
const options = parseCommandLine(['--includeCompletionsForModuleExports', 'false', '--help']); | ||
expect(options.includeCompletionsForModuleExports).toEqual(false); | ||
}); | ||
}); |
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 LSP test has passed. Currently, the CI error is due to a timeout issue.
@atscott It's ready for review.