Class: Mui::Lsp::ServerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/mui/lsp/server_config.rb

Overview

Configuration for different LSP servers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, command:, language_ids:, file_patterns:, auto_start: true, sync_on_change: true) ⇒ ServerConfig

Returns a new instance of ServerConfig.



9
10
11
12
13
14
15
16
# File 'lib/mui/lsp/server_config.rb', line 9

def initialize(name:, command:, language_ids:, file_patterns:, auto_start: true, sync_on_change: true)
  @name = name
  @command = command
  @language_ids = Array(language_ids)
  @file_patterns = Array(file_patterns)
  @auto_start = auto_start
  @sync_on_change = sync_on_change
end

Instance Attribute Details

#auto_startObject (readonly)

Returns the value of attribute auto_start.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def auto_start
  @auto_start
end

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def command
  @command
end

#file_patternsObject (readonly)

Returns the value of attribute file_patterns.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def file_patterns
  @file_patterns
end

#language_idsObject (readonly)

Returns the value of attribute language_ids.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def language_ids
  @language_ids
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def name
  @name
end

#sync_on_changeObject (readonly)

Returns the value of attribute sync_on_change.



7
8
9
# File 'lib/mui/lsp/server_config.rb', line 7

def sync_on_change
  @sync_on_change
end

Class Method Details

.custom(name:, command:, language_ids:, file_patterns:, auto_start: true, sync_on_change: true) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/mui/lsp/server_config.rb', line 102

def custom(name:, command:, language_ids:, file_patterns:, auto_start: true, sync_on_change: true)
  new(
    name: name,
    command: command,
    language_ids: language_ids,
    file_patterns: file_patterns,
    auto_start: auto_start,
    sync_on_change: sync_on_change
  )
end

.kanayago(auto_start: false) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/mui/lsp/server_config.rb', line 82

def kanayago(auto_start: false)
  new(
    name: "kanayago",
    command: "kanayago --lsp",
    language_ids: ["ruby"],
    file_patterns: ["**/*.rb", "**/*.rake", "**/Gemfile", "**/Rakefile", "**/*.gemspec"],
    auto_start: auto_start
  )
end

.rubocop_lsp(auto_start: false) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/mui/lsp/server_config.rb', line 92

def rubocop_lsp(auto_start: false)
  new(
    name: "rubocop",
    command: "rubocop --lsp",
    language_ids: ["ruby"],
    file_patterns: ["**/*.rb", "**/*.rake", "**/Gemfile", "**/Rakefile", "**/*.gemspec"],
    auto_start: auto_start
  )
end

.ruby_lsp(auto_start: false, sync_on_change: false) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/mui/lsp/server_config.rb', line 71

def ruby_lsp(auto_start: false, sync_on_change: false)
  new(
    name: "ruby-lsp",
    command: "ruby-lsp",
    language_ids: ["ruby"],
    file_patterns: ["**/*.rb", "**/*.rake", "**/Gemfile", "**/Rakefile", "**/*.gemspec"],
    auto_start: auto_start,
    sync_on_change: sync_on_change
  )
end

.solargraph(auto_start: false) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/mui/lsp/server_config.rb', line 61

def solargraph(auto_start: false)
  new(
    name: "solargraph",
    command: "solargraph stdio",
    language_ids: ["ruby"],
    file_patterns: ["**/*.rb", "**/*.rake", "**/Gemfile", "**/Rakefile", "**/*.gemspec"],
    auto_start: auto_start
  )
end

Instance Method Details

#handles_file?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/mui/lsp/server_config.rb', line 18

def handles_file?(file_path)
  @file_patterns.any? do |pattern|
    File.fnmatch?(pattern, file_path, File::FNM_PATHNAME | File::FNM_EXTGLOB)
  end
end

#language_id_for(file_path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mui/lsp/server_config.rb', line 24

def language_id_for(file_path)
  ext = File.extname(file_path).downcase
  case ext
  when ".rb", ".rake", ".gemspec", ".ru"
    "ruby"
  when ".js"
    "javascript"
  when ".ts"
    "typescript"
  when ".py"
    "python"
  when ".go"
    "go"
  when ".rs"
    "rust"
  when ".c"
    "c"
  when ".cpp", ".cc", ".cxx"
    "cpp"
  when ".java"
    "java"
  else
    @language_ids.first
  end
end

#to_hObject



50
51
52
53
54
55
56
57
58
# File 'lib/mui/lsp/server_config.rb', line 50

def to_h
  {
    name: @name,
    command: @command,
    language_ids: @language_ids,
    file_patterns: @file_patterns,
    auto_start: @auto_start
  }
end