Sha256: 5011dd19e4ad9ed2f71b8e93ea9d14042e8d399b59a12c2d1a5bec69fc52af09

Contents?: true

Size: 981 Bytes

Versions: 4

Compression:

Stored size: 981 Bytes

Contents

module Yoda
  module Cli
    class Complete < Base
      include FileCursorParsable

      attr_reader :filename_with_position

      # @param filename_with_position [String] position representation with the format `path/to/file:line_num:character_num`
      def initialize(filename_with_position)
        @filename_with_position = filename_with_position
      end

      def run
        project.setup
        puts create_completions(worker.candidates)
      end

      private

      # @param completion_item [Model::CompletionItem]
      # @return [String, nil]
      def create_completions(completion_item)
        completion_item.join("\n")
      end

      def worker
        @worker ||= Services::CodeCompletion.new(project.environment, source, position)
      end

      def project
        @project ||= Store::Project.for_path(Dir.pwd)
      end

      def source
        Parsing.fix_parse_error(source: File.read(filename), location: position)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/cli/complete.rb
yoda-language-server-0.10.0 lib/yoda/cli/complete.rb
yoda-language-server-0.9.0 lib/yoda/cli/complete.rb
yoda-language-server-0.8.0 lib/yoda/cli/complete.rb