The Wayback Machine - https://web.archive.org/web/20210806170148/https://github.com/angular/angular/pull/42729
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

feat(language-service): support autocomplete string literal union typ… #42729

Conversation

@ivanwonder
Copy link
Contributor

@ivanwonder ivanwonder commented Jul 1, 2021

…es in templates

The native TS language service has the ability to provide autocompletions for
string literal union types. This pr is for Angular to do the same in templates.

Fixes angular/vscode-ng-language-service#1096

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Jul 1, 2021
@pullapprove pullapprove bot requested review from AndrewKushnir and atscott Jul 1, 2021
@ivanwonder ivanwonder force-pushed the ivanwonder:autocomplete-string-literal-union-types branch from 43fb8fe to cee87c2 Jul 1, 2021
@ngbot ngbot bot added this to the Backlog milestone Jul 1, 2021
@atscott atscott requested a review from zarend Jul 1, 2021
@atscott
Copy link
Contributor

@atscott atscott commented Jul 1, 2021

@zarend - Can you give this PR an initial review? I believe #41456 was supposed to fix this already. We should investigate why that didn't do the trick for the case here and determine if we need to consolidate the approaches rather than doing similar things in two different places.

@ivanwonder
Copy link
Contributor Author

@ivanwonder ivanwonder commented Jul 5, 2021

I don't notice there have a pr for it. I think the reason is the vscode does not trigger suggest here [myInput]="¦" by ". This PR provides suggestions only when the users input a string [myInput]="'¦'", It's a little different from the 41456. And this myInput="one" is a special case.

@ivanwonder ivanwonder force-pushed the ivanwonder:autocomplete-string-literal-union-types branch from ef9e809 to 57704fd Jul 6, 2021
@ivanwonder
Copy link
Contributor Author

@ivanwonder ivanwonder commented Jul 6, 2021

I add a new commit to fix a bug of #41456

Copy link
Contributor

@zarend zarend left a comment

Autocompleting string literal union types was already implemented in #41456. AFAIK, the current implementation works fine, except that is does not support string union types in binding without brackets. We could consolidate approaches to make this works for bindings without brackets. i imagine angular developers would find that helpful.

Requesting changes because this feature should not be a special case at the completion builder level. we should first detect if we're completing the value of an attribute, then detect if we can complete a string literal value.

Copy link
Contributor

@atscott atscott left a comment

👍 I think this is the right direction overall.

packages/language-service/ivy/completions.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/completions.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/completions.ts Outdated Show resolved Hide resolved
@ivanwonder ivanwonder force-pushed the ivanwonder:autocomplete-string-literal-union-types branch from a9c9318 to a318416 Jul 15, 2021
@ivanwonder ivanwonder force-pushed the ivanwonder:autocomplete-string-literal-union-types branch 2 times, most recently from 1d15835 to 133fcaf Jul 21, 2021
@google-cla
Copy link

@google-cla google-cla bot commented Jul 22, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Jul 22, 2021
@google-cla
Copy link

@google-cla google-cla bot commented Jul 23, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@atscott atscott force-pushed the ivanwonder:autocomplete-string-literal-union-types branch from 76810ba to 350fa4a Jul 23, 2021
@google-cla google-cla bot added cla: yes and removed cla: no labels Jul 23, 2021
@atscott atscott dismissed zarend’s stale review Jul 23, 2021

addressed comments

@atscott
Copy link
Contributor

@atscott atscott commented Jul 23, 2021

@zarend
zarend approved these changes Jul 27, 2021
Copy link
Contributor

@zarend zarend left a comment

Awesome work. the implementation looks good, couldn't find anything wrong with it. I left a few comments about the tests, and I did more testing of this on my machine.

Are pipe arguments supposed to work, or is that out-of-scope? i couldn't get this to complete a pipe argument

transform(value: string, config: 'foo' | 'bar'): string // pipe defn
756 const {templateFile} = setup({{ foo | anotherPipe:"" }}, '', ANOTHER_PIPE); // pipe usage

…es in templates

The native TS language service has the ability to provide autocompletions for
string literal union types. This pr is for Angular to do the same in templates.

Fixes angular/vscode-ng-language-service#1096
@ivanwonder ivanwonder force-pushed the ivanwonder:autocomplete-string-literal-union-types branch from 350fa4a to 9fbd42b Jul 27, 2021
it('should complete a string union types in pipe', () => {
const {templateFile} =
setup(`<input dir [myInput]="'foo'|unionTypePipe:'bar'">`, '', UNION_TYPE_PIPE);
templateFile.moveCursorToText(`[myInput]="'foo'|unionTypePipe:'bar¦'"`);
const completions = templateFile.getCompletionsAtPosition();
expectContain(completions, ts.ScriptElementKind.string, ['bar']);
expectReplacementText(completions, templateFile.contents, 'bar');
});
Comment on lines +792 to +799

This comment has been minimized.

@ivanwonder

ivanwonder Jul 27, 2021
Author Contributor

@zarend Maybe is your configuration of ANOTHER_PIPE wrong?

@atscott atscott removed the request for review from AndrewKushnir Jul 28, 2021
@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented Jul 28, 2021

The caretaker tool insists that because this has feat commits, it needs to go in the minor.

@dylhunn dylhunn closed this in 7c35ca0 Jul 28, 2021
@ivanwonder ivanwonder deleted the ivanwonder:autocomplete-string-literal-union-types branch Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants