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,
  },
  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.



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

def initialize(server)
  @server = server
  @previously_reported_files = Set.new
  @storage = InMemoryStorage.new
  @completion_engine = CompletionEngine.new(@storage)
end

Instance Method Details

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



37
38
39
# File 'lib/theme_check/language_server/handler.rb', line 37

def on_exit(_id, _params)
  close!
end

#on_initialize(id, params) ⇒ Object



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

def on_initialize(id, params)
  @root_path = params["rootPath"]
  # 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



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

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

#on_text_document_did_change(_id, params) ⇒ Object



42
43
44
45
# File 'lib/theme_check/language_server/handler.rb', line 42

def on_text_document_did_change(_id, params)
  uri = text_document_uri(params)
  @storage.write(uri, content_changes_text(params))
end

#on_text_document_did_close(_id, params) ⇒ Object



47
48
49
50
# File 'lib/theme_check/language_server/handler.rb', line 47

def on_text_document_did_close(_id, params)
  uri = text_document_uri(params)
  @storage.write(uri, nil)
end

#on_text_document_did_open(_id, params) ⇒ Object



52
53
54
55
56
# File 'lib/theme_check/language_server/handler.rb', line 52

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

#on_text_document_did_save(_id, params) ⇒ Object



58
59
60
# File 'lib/theme_check/language_server/handler.rb', line 58

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