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

Auto-suggest should never pop up after case statements #705

Closed
3 tasks done
ffxsam opened this issue Feb 25, 2018 · 7 comments
Closed
3 tasks done

Auto-suggest should never pop up after case statements #705

ffxsam opened this issue Feb 25, 2018 · 7 comments

Comments

@ffxsam
Copy link

ffxsam commented Feb 25, 2018

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: macOS 10.13.3
  • Vetur version: 0.11.7
  • VS Code version: 1.20.1

Problem

Auto suggest pops up every time after case (and default) statements. This is highly annoying as we have to hit ESC after every single case statement.

screencap

Reproducible Case

  1. Open .vue file
  2. Navigate to script block
  3. Create a switch block, and start entering case statements
@HerringtonDarkholme
Copy link
Member

Sadly vscode only supports one set of completion trigger:

https://github.com/vuejs/vetur/blob/master/server/src/vueServerMain.ts#L58

We need to add : in completion triggers for template completion.

@ffxsam
Copy link
Author

ffxsam commented Feb 26, 2018

@HerringtonDarkholme I don't understand. This autocompletion for case statements doesn't happen in regular JS files. Could you elaborate on why this happens in Vetur?

@octref
Copy link
Member

octref commented Feb 26, 2018

This happens because we use a superset of completion triggers for html/css/js in Vetur. Completion triggers are like . (for js properties), < (for html tags). We added : for :foo completions in Vue template.

I'll open an upstream issue to track this.

@octref octref reopened this Feb 26, 2018
@octref octref added upstream and removed wontfix labels Feb 26, 2018
@ffxsam
Copy link
Author

ffxsam commented Feb 26, 2018

Thanks! Makes sense that the : completion trigger would only work in the <template> block and not the <script> block.. but it sounds like a VS Code limitation.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Feb 26, 2018

That's not possible in VSCode now. And it is not supported in most editors as far as I know. Few editors place mixed language file in the first place.

On the other hand, dynamically changing completion triggers isn't the most sensible choice. The only use case I can see is mixed language.

So the problem is better modeled as how to support mixed language in editors. Say, JS in HTML, SQL in PHP. Other than triggering completion, there are other issues related to mixed language. For example, how to count consecutive characters as one word, and emmet expansion in JS/html/css, comment toggling. One direct way to detect language is by syntax highlighting.

For @ffxsam 's issue, I suggest you to separate another file for media processing, if they are not involved in UI logic. If they are, a hash table is probably better than switch case.

Prior art:

https://github.com/purcell/mmm-mode
https://github.com/Shougo/context_filetype.vim/blob/master/doc/context_filetype.txt

@octref
Copy link
Member

octref commented Feb 26, 2018

Umm this naive way of doing it seems to be working:

connection.onCompletion(textDocumentPosition => {
  const document = documents.get(textDocumentPosition.textDocument.uri);
  const offset = document.offsetAt(
    Position.create(textDocumentPosition.position.line, textDocumentPosition.position.character - 1)
  );
  const triggerChar = document.getText()[offset];
  if (triggerChar === ':') {
    return { isIncomplete: false, items: [] };
  }
  return vls.doComplete(document, textDocumentPosition.position);
});

I can put it in js/ts mode to return empty suggestions when trigger characters aren't js/ts trigger characters.

HerringtonDarkholme added a commit that referenced this issue Mar 3, 2018
 fix #705, skip template completion trigger in script
@octref
Copy link
Member

octref commented Mar 6, 2018

When we upgrade to LS 4.0 we can use the CompletionContext, see https://microsoft.github.io/language-server-protocol/specification#completion-request-leftwards_arrow_with_hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants