Skip to content

Commit 96878de

Browse files
committed
feat: provide snippets for attribute
1 parent 6b8d49e commit 96878de

File tree

6 files changed

+30
-3
lines changed

6 files changed

+30
-3
lines changed

client/src/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
454454
args.push('--includeAutomaticOptionalChainCompletions');
455455
}
456456

457+
const includeCompletionsWithSnippetText =
458+
config.get<boolean>('angular.suggest.includeCompletionsWithSnippetText');
459+
if (includeCompletionsWithSnippetText) {
460+
args.push('--includeCompletionsWithSnippetText');
461+
}
462+
457463
const tsdk: string|null = config.get('typescript.tsdk', null);
458464
const tsProbeLocations = getProbeLocations(tsdk, ctx.extensionPath);
459465
args.push('--tsProbeLocations', tsProbeLocations.join(','));

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
"type": "boolean",
119119
"default": true,
120120
"description": "Enable/disable showing completions on potentially undefined values that insert an optional chain call. Requires TS 3.7+ and strict null checks to be enabled."
121+
},
122+
"angular.suggest.includeCompletionsWithSnippetText": {
123+
"type": "boolean",
124+
"default": true,
125+
"description": "Enable/disable snippet completions from angular language Server. Requires using TypeScript 4.3+ in the workspace."
121126
}
122127
}
123128
},

server/src/cmdline_utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface CommandLineOptions {
3838
ngProbeLocations: string[];
3939
tsProbeLocations: string[];
4040
includeAutomaticOptionalChainCompletions: boolean;
41+
includeCompletionsWithSnippetText: boolean;
4142
}
4243

4344
export function parseCommandLine(argv: string[]): CommandLineOptions {
@@ -51,6 +52,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
5152
tsProbeLocations: parseStringArray(argv, '--tsProbeLocations'),
5253
includeAutomaticOptionalChainCompletions:
5354
hasArgument(argv, '--includeAutomaticOptionalChainCompletions'),
55+
includeCompletionsWithSnippetText: hasArgument(argv, '--includeCompletionsWithSnippetText'),
5456
};
5557
}
5658

server/src/completion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ export function tsCompletionEntryToLspCompletionItem(
125125
// range will include the dot. the `insertText` should be assigned to the `filterText` to filter
126126
// the completion items.
127127
item.filterText = entry.insertText;
128+
if (entry.isSnippet) {
129+
item.insertTextFormat = lsp.InsertTextFormat.Snippet;
130+
}
128131
}
129132

130133
item.data = {

server/src/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function main() {
4444
resolvedNgLsPath: ng.resolvedPath,
4545
ivy: isG3 ? true : options.ivy,
4646
logToConsole: options.logToConsole,
47-
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions
47+
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
48+
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
4849
});
4950

5051
// Log initialization info

server/src/session.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface SessionOptions {
3131
ivy: boolean;
3232
logToConsole: boolean;
3333
includeAutomaticOptionalChainCompletions: boolean;
34+
includeCompletionsWithSnippetText: boolean;
3435
}
3536

3637
enum LanguageId {
@@ -55,6 +56,8 @@ export class Session {
5556
private readonly logToConsole: boolean;
5657
private readonly openFiles = new MruTracker();
5758
private readonly includeAutomaticOptionalChainCompletions: boolean;
59+
private readonly includeCompletionsWithSnippetText: boolean;
60+
private snippetSupport: boolean|undefined;
5861
// Tracks the spawn order and status of the `ngcc` processes. This allows us to ensure we enable
5962
// the LS in the same order the projects were created in.
6063
private projectNgccQueue: Array<{project: ts.server.Project, done: boolean}> = [];
@@ -72,6 +75,7 @@ export class Session {
7275
constructor(options: SessionOptions) {
7376
this.includeAutomaticOptionalChainCompletions =
7477
options.includeAutomaticOptionalChainCompletions;
78+
this.includeCompletionsWithSnippetText = options.includeCompletionsWithSnippetText;
7579
this.logger = options.logger;
7680
this.ivy = options.ivy;
7781
this.logToConsole = options.logToConsole;
@@ -604,6 +608,8 @@ export class Session {
604608
}
605609

606610
private onInitialize(params: lsp.InitializeParams): lsp.InitializeResult {
611+
this.snippetSupport =
612+
params.capabilities.textDocument?.completion?.completionItem?.snippetSupport;
607613
const serverOptions: ServerOptions = {
608614
logFile: this.logger.getLogFileName(),
609615
};
@@ -1006,10 +1012,14 @@ export class Session {
10061012
const offset = lspPositionToTsPosition(scriptInfo, params.position);
10071013

10081014
let options: ts.GetCompletionsAtPositionOptions = {};
1009-
if (this.includeAutomaticOptionalChainCompletions) {
1015+
const includeCompletionsWithSnippetText =
1016+
this.includeCompletionsWithSnippetText && this.snippetSupport;
1017+
if (this.includeAutomaticOptionalChainCompletions || includeCompletionsWithSnippetText) {
10101018
options = {
10111019
includeAutomaticOptionalChainCompletions: this.includeAutomaticOptionalChainCompletions,
1012-
includeCompletionsWithInsertText: this.includeAutomaticOptionalChainCompletions,
1020+
includeCompletionsWithSnippetText: this.includeCompletionsWithSnippetText,
1021+
includeCompletionsWithInsertText:
1022+
this.includeAutomaticOptionalChainCompletions || this.includeCompletionsWithSnippetText,
10131023
};
10141024
}
10151025

0 commit comments

Comments
 (0)