Sha256: a8a2f4a7703a2756b88182d4c084a42c8a8629caa1af4d1551f78b767b4a1802

Contents?: true

Size: 1.07 KB

Versions: 36

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    class RenderSnippetCompletionProvider < CompletionProvider
      def completions(content, cursor)
        return [] unless cursor_on_quoted_argument?(content, cursor)
        partial = snippet(content) || ''
        snippets
          .select { |x| x.start_with?(partial) }
          .map { |x| snippet_to_completion(x) }
      end

      private

      def cursor_on_quoted_argument?(content, cursor)
        match = content.match(PARTIAL_RENDER)
        return false if match.nil?
        match.begin(:partial) <= cursor && cursor <= match.end(:partial)
      end

      def snippet(content)
        match = content.match(PARTIAL_RENDER)
        return if match.nil?
        match[:partial]
      end

      def snippets
        @storage
          .files
          .select { |x| x.include?('snippets/') }
      end

      def snippet_to_completion(file)
        {
          label: File.basename(file, '.liquid'),
          kind: CompletionItemKinds::SNIPPET,
          detail: file,
        }
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
theme-check-1.2.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-1.1.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-1.0.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.10.2 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.10.1 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.10.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.9.1 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.9.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.8.3 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.8.2 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.8.1 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.8.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.7.3 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.7.2 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.7.1 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb
theme-check-0.7.0 lib/theme_check/language_server/completion_providers/render_snippet_completion_provider.rb