Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Complete in strings and comments #55

Open
@lalomartins

Description

@lalomartins

I'd like to be able to write snippets for strings and comments. For example, language-coffee-script has a snippet for "#{interpolation}" which doesn't work so it had to hack around it somehow (I'm not quite sure how, couldn't find it in the source). Some snippets, such as lorem and legal, are clearly only useful (in source code files) inside a string or comment.

Currently it's not possible to complete in strings and comments, due to disableForSelector: '.comment, .string'. Furthermore, since autocomplete+ hijacks tab from snippets, I can't trigger the snippet by hand with tab either, if there's a symbol (fuzzy-)matching the snippet name.

I believe that does more harm than good; if the symbol provider works in strings and comments, why not snippets?

Even if it turns out people really don't like them, I'd suggest an alternative implementation is to match only snippets that actually have .string or .comment in the selector. Hacking around the devtools console, I managed to make that happen by passing only the current scope as the scope option to config.get. I managed to make that happen with the following code:

  getSuggestions: ({scopeDescriptor, prefix}) ->
    return unless prefix?.length
    isStringOrComment = scopeDescriptor.getScopeChain().match(/\s([^ ]*\.(string|comment)\b[^ ]*)$/)
    if isStringOrComment
      # could also use isStringOrComment[1]
      scopes = scopeDescriptor.getScopesArray()
      scopeDescriptor = [scopes[scopes.length - 1]]
    scopeSnippets = atom.config.get('snippets', {scope: scopeDescriptor})
    @findSuggestionsForPrefix(scopeSnippets, prefix)

(Not very happy with using a regex, but I couldn't find an API to check for a selector match; then again personally I'd rather not have this hack at all, just enable the provider and leave it at that.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions