Class: ThemeCheck::LanguageServer::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/language_server/handler.rb

Constant Summary collapse

CAPABILITIES =
{
  completionProvider: {
    triggerCharacters: ['.', '{{ ', '{% '],
    context: true,
  },
  documentLinkProvider: true,
  textDocumentSync: {
    openClose: true,
    change: TextDocumentSyncKind::FULL,
    willSave: false,
    save: true,
  },
}

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Handler

Returns a new instance of Handler.



20
21
22
23
# File 'lib/theme_check/language_server/handler.rb', line 20

def initialize(server)
  @server = server
  @previously_reported_files = Set.new
end

Instance Method Details

#on_exit(_id, _params) ⇒ Object Also known as: on_shutdown



39
40
41
# File 'lib/theme_check/language_server/handler.rb', line 39

def on_exit(_id, _params)
  close!
end

#on_initialize(id, params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/theme_check/language_server/handler.rb', line 25

def on_initialize(id, params)
  @root_path = params["rootPath"]
  @storage = in_memory_storage(@root_path)
  @completion_engine = CompletionEngine.new(@storage)
  @document_link_engine = DocumentLinkEngine.new(@storage)
  # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
  send_response(
    id: id,
    result: {
      capabilities: CAPABILITIES,
    }
  )
end

#on_text_document_completion(id, params) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/theme_check/language_server/handler.rb', line 72

def on_text_document_completion(id, params)
  relative_path = relative_path_from_text_document_uri(params)
  line = params.dig('position', 'line')
  col = params.dig('position', 'character')
  send_response(
    id: id,
    result: completions(relative_path, line, col)
  )
end

#on_text_document_did_change(_id, params) ⇒ Object



44
45
46
47
# File 'lib/theme_check/language_server/handler.rb', line 44

def on_text_document_did_change(_id, params)
  relative_path = relative_path_from_text_document_uri(params)
  @storage.write(relative_path, content_changes_text(params))
end

#on_text_document_did_close(_id, params) ⇒ Object



49
50
51
52
# File 'lib/theme_check/language_server/handler.rb', line 49

def on_text_document_did_close(_id, params)
  relative_path = relative_path_from_text_document_uri(params)
  @storage.write(relative_path, "")
end

#on_text_document_did_open(_id, params) ⇒ Object



54
55
56
57
58
# File 'lib/theme_check/language_server/handler.rb', line 54

def on_text_document_did_open(_id, params)
  relative_path = relative_path_from_text_document_uri(params)
  @storage.write(relative_path, text_document_text(params))
  analyze_and_send_offenses(text_document_uri(params))
end

#on_text_document_did_save(_id, params) ⇒ Object



60
61
62
# File 'lib/theme_check/language_server/handler.rb', line 60

def on_text_document_did_save(_id, params)
  analyze_and_send_offenses(text_document_uri(params))
end


64
65
66
67
68
69
70
# File 'lib/theme_check/language_server/handler.rb', line 64

def on_text_document_document_link(id, params)
  relative_path = relative_path_from_text_document_uri(params)
  send_response(
    id: id,
    result: document_links(relative_path)
  )
end