Class: LSP::CompletionItem

Inherits:
LSPBase
  • Object
show all
Defined in:
lib/lsp/lsp_types.rb

Overview

export interface CompletionItem

/**
 * The label of this completion item. By default
 * also the text that is inserted when selecting
 * this completion.
 */
label: string;
/**
 * The kind of this completion item. Based of the kind
 * an icon is chosen by the editor.
 */
kind?: CompletionItemKind;
/**
 * Tags for this completion item.
 *
 * @since 3.15.0
 */
tags?: CompletionItemTag[];
/**
 * A human-readable string with additional information
 * about this item, like type or symbol information.
 */
detail?: string;
/**
 * A human-readable string that represents a doc-comment.
 */
documentation?: string | MarkupContent;
/**
 * Indicates if this item is deprecated.
 * @deprecated Use `tags` instead.
 */
deprecated?: boolean;
/**
 * Select this item when showing.
 *
 * *Note* that only one completion item can be selected and that the
 * tool / client decides which item that is. The rule is that the *first*
 * item of those that match best is selected.
 */
preselect?: boolean;
/**
 * A string that should be used when comparing this item
 * with other items. When `falsy` the [label](#CompletionItem.label)
 * is used.
 */
sortText?: string;
/**
 * A string that should be used when filtering a set of
 * completion items. When `falsy` the [label](#CompletionItem.label)
 * is used.
 */
filterText?: string;
/**
 * A string that should be inserted into a document when selecting
 * this completion. When `falsy` the [label](#CompletionItem.label)
 * is used.
 *
 * The `insertText` is subject to interpretation by the client side.
 * Some tools might not take the string literally. For example
 * VS Code when code complete is requested in this example `con<cursor position>`
 * and a completion item with an `insertText` of `console` is provided it
 * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
 * since it avoids additional client side interpretation.
 */
insertText?: string;
/**
 * The format of the insert text. The format applies to both the `insertText` property
 * and the `newText` property of a provided `textEdit`. If ommitted defaults to
 * `InsertTextFormat.PlainText`.
 */
insertTextFormat?: InsertTextFormat;
/**
 * An [edit](#TextEdit) which is applied to a document when selecting
 * this completion. When an edit is provided the value of
 * [insertText](#CompletionItem.insertText) is ignored.
 *
 * *Note:* The text edit's range must be a [single line] and it must contain the position
 * at which completion has been requested.
 */
textEdit?: TextEdit;
/**
 * An optional array of additional [text edits](#TextEdit) that are applied when
 * selecting this completion. Edits must not overlap (including the same insert position)
 * with the main [edit](#CompletionItem.textEdit) nor with themselves.
 *
 * Additional text edits should be used to change text unrelated to the current cursor position
 * (for example adding an import statement at the top of the file if the completion item will
 * insert an unqualified type).
 */
additionalTextEdits?: TextEdit[];
/**
 * An optional set of characters that when pressed while this completion is active will accept it first and
 * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
 * characters will be ignored.
 */
commitCharacters?: string[];
/**
 * An optional [command](#Command) that is executed *after* inserting this completion. *Note* that
 * additional modifications to the current document should be described with the
 * [additionalTextEdits](#CompletionItem.additionalTextEdits)-property.
 */
command?: Command;
/**
 * An data entry field that is preserved on a completion item between
 * a [CompletionRequest](#CompletionRequest) and a [CompletionResolveRequest]
 * (#CompletionResolveRequest)
 */
data?: any;

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from LSPBase

#to_h, #to_json

Constructor Details

#initialize(initial_hash = nil) ⇒ CompletionItem

Returns a new instance of CompletionItem.



860
861
862
863
# File 'lib/lsp/lsp_types.rb', line 860

def initialize(initial_hash = nil)
  super
  @optional_method_names = i[kind tags detail documentation deprecated preselect sortText filterText insertText insertTextFormat textEdit additionalTextEdits commitCharacters command data]
end

Instance Attribute Details

#additionalTextEditsObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def additionalTextEdits
  @additionalTextEdits
end

#commandObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def command
  @command
end

#commitCharactersObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def commitCharacters
  @commitCharacters
end

#dataObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def data
  @data
end

#deprecatedObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def deprecated
  @deprecated
end

#detailObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def detail
  @detail
end

#documentationObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def documentation
  @documentation
end

#filterTextObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def filterText
  @filterText
end

#insertTextObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def insertText
  @insertText
end

#insertTextFormatObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def insertTextFormat
  @insertTextFormat
end

#kindObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def kind
  @kind
end

#labelObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def label
  @label
end

#preselectObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def preselect
  @preselect
end

#sortTextObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def sortText
  @sortText
end

#tagsObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def tags
  @tags
end

#textEditObject

type: string # type: CompletionItemKind # type: CompletionItemTag[] # type: string # type: string | MarkupContent # type: boolean # type: boolean # type: string # type: string # type: string # type: InsertTextFormat # type: TextEdit # type: TextEdit[] # type: string[] # type: Command # type: any



858
859
860
# File 'lib/lsp/lsp_types.rb', line 858

def textEdit
  @textEdit
end

Instance Method Details

#from_h!(value) ⇒ Object



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/lsp/lsp_types.rb', line 865

def from_h!(value)
  value = {} if value.nil?
  self.label = value['label']
  self.kind = value['kind'] # Unknown type
  self.tags = value['tags'].map { |val| val } unless value['tags'].nil? # Unknown array type
  self.detail = value['detail']
  self.documentation = value['documentation'] # Unknown type
  self.deprecated = value['deprecated'] # Unknown type
  self.preselect = value['preselect'] # Unknown type
  self.sortText = value['sortText']
  self.filterText = value['filterText']
  self.insertText = value['insertText']
  self.insertTextFormat = value['insertTextFormat'] # Unknown type
  self.textEdit = TextEdit.new(value['textEdit']) unless value['textEdit'].nil?
  self.additionalTextEdits = to_typed_aray(value['additionalTextEdits'], TextEdit)
  self.commitCharacters = value['commitCharacters'].map { |val| val } unless value['commitCharacters'].nil?
  self.command = Command.new(value['command']) unless value['command'].nil?
  self.data = value['data']
  self
end