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

Allow scoped snippet #15287

Closed
octref opened this issue Nov 10, 2016 · 5 comments
Closed

Allow scoped snippet #15287

octref opened this issue Nov 10, 2016 · 5 comments
Labels
*extension-candidate Issue identified as good extension implementation feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@octref
Copy link
Contributor

octref commented Nov 10, 2016

Sublime allows snippet for particular scopes: http://docs.sublimetext.info/en/latest/extensibility/snippets.html

This is particularly useful for embedded languages like vue.js:

<template>
  <div id="app">
    Clicked: {{ $store.state.count }} times, count is {{ evenOrOdd }}.
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="incrementIfOdd">Increment if odd</button>
    <button @click="incrementAsync">Increment async</button>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
export default {
  computed: mapGetters([
    'evenOrOdd'
  ]),
  methods: mapActions([
    'increment',
    'decrement',
    'incrementIfOdd',
    'incrementAsync'
  ])
}
</script>
@octref octref added the feature-request Request for new features or functionality label Nov 10, 2016
@alexdima
Copy link
Member

This can be implemented from an extension that registers a completion item provider that is smart enough to suggest certain snippets only in certain locations.

@alexdima alexdima added the *extension-candidate Issue identified as good extension implementation label Nov 30, 2016
@alexdima alexdima added this to the Backlog milestone Nov 30, 2016
@alexdima alexdima removed their assignment Nov 30, 2016
@siegebell
Copy link

@alexandrudima I see no generic way for an extension to do this until #580 is resolved.

@octref
Copy link
Contributor Author

octref commented Nov 16, 2017

@alexandrudima Well, now the user who wants to make a snippet only available to a certain part of his code has to:

  • Re-parse the code using vscode-textmate on each document change (which can be slow)
  • Get a parser for the snippets (the one bundled with VS Code can't be easily used standalone)
  • Write a CompletionItemProvider that provides the parsed snippets as CompletionItem if scope matches.

That's a lot of work and the extension will be slow.

@alexdima
Copy link
Member

alexdima commented Nov 17, 2017

@octref It is not in our best interest to further leak TM scopes in APIs or build more and more features on top of TM scopes:

We want at one point to be able to colorize using something else that doesn't have the problems and baggage of TM. For example, TM coloring is one our biggest perf detractors.

@octref
Copy link
Contributor Author

octref commented Nov 22, 2017

OK I'll close this as out-of-scope since I don't see we replacing TM anytime soon.
Sublime does have this since they have their own rule engine.
Meanwhile I'm doing scoped snippets in Vue using my own parser.

@octref octref closed this as completed Nov 22, 2017
@octref octref added the *out-of-scope Posted issue is not in scope of VS Code label Nov 22, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

3 participants