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

[WIP] feat(completion): improve auto complete in html template #1736

Closed
wants to merge 1 commit into from

Conversation

pikax
Copy link
Member

@pikax pikax commented Feb 27, 2020

Improving auto completion on html, based on the component definition.

Implemented

  • Provide deep member properties

TODO

  • Support auto-completion when is expression

image

image
image

image

example:

<template>
  <div>
    <p v-if="obj.ourdata"></p>
  </div>
</template>

<script>
import { defineComponent } from "@vue/composition-api";

export default defineComponent({
  data() {
    return {
      mydata: "1",
      obj: {
        ourdata: 2,
        supa: {
          a: "a",
          n: 1122
        }
      }
    };
  },
  computed: {
    test() {
      return 1;
    },
    testObj() {
      return {
        a: 1,
        bb: {
          a: "2"
        }
      };
    }
  }
});
</script>

@pikax pikax changed the title ]feat(completion): improve auto complete in html template [WIP] feat(completion): improve auto complete in html template Feb 27, 2020
@ktsn
Copy link
Member

ktsn commented Feb 27, 2020

Hmm, I don't think we should manually analyze data properties...
We should utilize type info to do that instead so that the behavior would be the same as normal typescript language feature and we don't have to reinvent the wheel.
And I had made such implementation earlier on this PR. #1446

@pikax
Copy link
Member Author

pikax commented Feb 28, 2020

If there's a way to get the autocomplete correctly from typescript, I completely agree on using that.

Checked your PR(still need time to understand it), only get the first level auto completion, I reckon is the

return checker.getPropertiesOfType(computedType).map(s => {
return {
name: s.name,
documentation: buildDocumentation(tsModule, s, checker)
};
});

Is not enough to get the the info for

result.set(p.name, {
label: p.name,
documentation: {
kind: 'markdown',
value: p.documentation || `\`${p.name}\` computed`
},
kind: CompletionItemKind.Property

To build the proper typing.

because as soon as you do:

<p v-if="obj.ou">

The templateService will return undefined.

const completions = templateService.getCompletionsAtPosition(templateFileFsPath, mappedOffset, {

Do you know any documentation that helps doing this?

@ktsn
Copy link
Member

ktsn commented Feb 28, 2020

You are seeing the current implementation that is even left in the PR for backward compatibility.

The main part of the completion is this line.
https://github.com/vuejs/vetur/pull/1446/files#diff-62e73e93316645d3d052a2638e515905R119
Just calling TS auto completion logic so that we can complete anything if the target is properly typed.

The nested property completion is confirmed by a test case in the PR as well.
https://github.com/vuejs/vetur/pull/1446/files#diff-01bc940b65f71e51cdbf9185aecefa8aR4

@pikax
Copy link
Member Author

pikax commented Feb 28, 2020

The nested property completion is confirmed by a test case in the PR as well.
https://github.com/vuejs/vetur/pull/1446/files#diff-01bc940b65f71e51cdbf9185aecefa8aR4

That example works, the example I was using, the typescript is not actually working -.-''

What's is needed for that PR to be merged?

@pikax pikax closed this Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants