solargraph 0.59.1 → 0.59.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +6 -0
- data/.github/workflows/plugins.yml +8 -0
- data/.github/workflows/typecheck.yml +2 -0
- data/CHANGELOG.md +7 -0
- data/lib/solargraph/api_map/store.rb +1 -2
- data/lib/solargraph/api_map.rb +4 -6
- data/lib/solargraph/complex_type/type_methods.rb +1 -0
- data/lib/solargraph/complex_type/unique_type.rb +12 -13
- data/lib/solargraph/complex_type.rb +1 -0
- data/lib/solargraph/convention/active_support_concern.rb +111 -111
- data/lib/solargraph/convention/base.rb +50 -50
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/environ.rb +52 -52
- data/lib/solargraph/gem_pins.rb +0 -11
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/initialized.rb +28 -28
- data/lib/solargraph/language_server/message/text_document.rb +28 -28
- data/lib/solargraph/language_server/progress.rb +143 -143
- data/lib/solargraph/language_server/transport/adapter.rb +68 -68
- data/lib/solargraph/language_server.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +20 -20
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/singleton.rb +11 -11
- data/lib/solargraph/rbs_map/conversions.rb +14 -7
- data/lib/solargraph/shell.rb +1 -1
- data/lib/solargraph/source/chain/array.rb +1 -12
- data/lib/solargraph/source/chain/block_symbol.rb +13 -13
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/head.rb +19 -19
- data/lib/solargraph/source/chain/literal.rb +18 -14
- data/lib/solargraph/source/source_chainer.rb +4 -4
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map/cache.rb +25 -25
- data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
- metadata +1 -2
- data/rbs/fills/tuple/tuple.rbs +0 -177
data/lib/solargraph/environ.rb
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
# A collection of additional data, such as map pins and required paths, that
|
|
5
|
-
# can be added to an ApiMap.
|
|
6
|
-
#
|
|
7
|
-
# Conventions are used to add Environs.
|
|
8
|
-
#
|
|
9
|
-
class Environ
|
|
10
|
-
# @return [Array<String>]
|
|
11
|
-
attr_reader :requires
|
|
12
|
-
|
|
13
|
-
# @return [Array<String>]
|
|
14
|
-
attr_reader :domains
|
|
15
|
-
|
|
16
|
-
# @return [Array<Pin::Base>]
|
|
17
|
-
attr_reader :pins
|
|
18
|
-
|
|
19
|
-
# @return [Array<String>]
|
|
20
|
-
attr_reader :yard_plugins
|
|
21
|
-
|
|
22
|
-
# @param requires [Array<String>]
|
|
23
|
-
# @param domains [Array<String>]
|
|
24
|
-
# @param pins [Array<Pin::Base>]
|
|
25
|
-
# @param yard_plugins [Array<String>]
|
|
26
|
-
def initialize requires: [], domains: [], pins: [], yard_plugins: []
|
|
27
|
-
@requires = requires
|
|
28
|
-
@domains = domains
|
|
29
|
-
@pins = pins
|
|
30
|
-
@yard_plugins = yard_plugins
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# @return [self]
|
|
34
|
-
def clear
|
|
35
|
-
domains.clear
|
|
36
|
-
requires.clear
|
|
37
|
-
pins.clear
|
|
38
|
-
yard_plugins.clear
|
|
39
|
-
self
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# @param other [Environ]
|
|
43
|
-
# @return [self]
|
|
44
|
-
def merge other
|
|
45
|
-
domains.concat other.domains
|
|
46
|
-
requires.concat other.requires
|
|
47
|
-
pins.concat other.pins
|
|
48
|
-
yard_plugins.concat other.yard_plugins
|
|
49
|
-
self
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
# A collection of additional data, such as map pins and required paths, that
|
|
5
|
+
# can be added to an ApiMap.
|
|
6
|
+
#
|
|
7
|
+
# Conventions are used to add Environs.
|
|
8
|
+
#
|
|
9
|
+
class Environ
|
|
10
|
+
# @return [Array<String>]
|
|
11
|
+
attr_reader :requires
|
|
12
|
+
|
|
13
|
+
# @return [Array<String>]
|
|
14
|
+
attr_reader :domains
|
|
15
|
+
|
|
16
|
+
# @return [Array<Pin::Base>]
|
|
17
|
+
attr_reader :pins
|
|
18
|
+
|
|
19
|
+
# @return [Array<String>]
|
|
20
|
+
attr_reader :yard_plugins
|
|
21
|
+
|
|
22
|
+
# @param requires [Array<String>]
|
|
23
|
+
# @param domains [Array<String>]
|
|
24
|
+
# @param pins [Array<Pin::Base>]
|
|
25
|
+
# @param yard_plugins [Array<String>]
|
|
26
|
+
def initialize requires: [], domains: [], pins: [], yard_plugins: []
|
|
27
|
+
@requires = requires
|
|
28
|
+
@domains = domains
|
|
29
|
+
@pins = pins
|
|
30
|
+
@yard_plugins = yard_plugins
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [self]
|
|
34
|
+
def clear
|
|
35
|
+
domains.clear
|
|
36
|
+
requires.clear
|
|
37
|
+
pins.clear
|
|
38
|
+
yard_plugins.clear
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param other [Environ]
|
|
43
|
+
# @return [self]
|
|
44
|
+
def merge other
|
|
45
|
+
domains.concat other.domains
|
|
46
|
+
requires.concat other.requires
|
|
47
|
+
pins.concat other.pins
|
|
48
|
+
yard_plugins.concat other.yard_plugins
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/solargraph/gem_pins.rb
CHANGED
|
@@ -11,17 +11,6 @@ module Solargraph
|
|
|
11
11
|
include Logging
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
# @param pins [Array<Pin::Base>]
|
|
15
|
-
# @return [Array<Pin::Base>]
|
|
16
|
-
def self.combine_method_pins_by_path pins
|
|
17
|
-
method_pins, alias_pins = pins.partition { |pin| pin.instance_of?(Pin::Method) }
|
|
18
|
-
by_path = method_pins.group_by(&:path)
|
|
19
|
-
by_path.transform_values! do |pins|
|
|
20
|
-
GemPins.combine_method_pins(*pins)
|
|
21
|
-
end
|
|
22
|
-
by_path.values + alias_pins
|
|
23
|
-
end
|
|
24
|
-
|
|
25
14
|
# @param pins [Array<Pin::Method>]
|
|
26
15
|
# @return [Pin::Method, nil]
|
|
27
16
|
def self.combine_method_pins(*pins)
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
module Extended
|
|
7
|
-
# Update YARD documentation for installed gems. If the `rebuild`
|
|
8
|
-
# parameter is true, rebuild existing yardocs.
|
|
9
|
-
#
|
|
10
|
-
class Environment < Base
|
|
11
|
-
def process
|
|
12
|
-
# Make sure the environment page can report RuboCop's version
|
|
13
|
-
require 'rubocop'
|
|
14
|
-
|
|
15
|
-
page = Solargraph::Page.new(host.options['viewsPath'])
|
|
16
|
-
content = page.render('environment', layout: true, locals: { config: host.options, folders: host.folders })
|
|
17
|
-
set_result(
|
|
18
|
-
content: content
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module Extended
|
|
7
|
+
# Update YARD documentation for installed gems. If the `rebuild`
|
|
8
|
+
# parameter is true, rebuild existing yardocs.
|
|
9
|
+
#
|
|
10
|
+
class Environment < Base
|
|
11
|
+
def process
|
|
12
|
+
# Make sure the environment page can report RuboCop's version
|
|
13
|
+
require 'rubocop'
|
|
14
|
+
|
|
15
|
+
page = Solargraph::Page.new(host.options['viewsPath'])
|
|
16
|
+
content = page.render('environment', layout: true, locals: { config: host.options, folders: host.folders })
|
|
17
|
+
set_result(
|
|
18
|
+
content: content
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
class Initialized < Base
|
|
7
|
-
def process
|
|
8
|
-
# @todo Temporarily removed textDocument/codeAction
|
|
9
|
-
host.register_capabilities %w[
|
|
10
|
-
textDocument/completion
|
|
11
|
-
textDocument/hover
|
|
12
|
-
textDocument/signatureHelp
|
|
13
|
-
textDocument/formatting
|
|
14
|
-
textDocument/documentSymbol
|
|
15
|
-
textDocument/definition
|
|
16
|
-
textDocument/typeDefinition
|
|
17
|
-
textDocument/references
|
|
18
|
-
textDocument/rename
|
|
19
|
-
textDocument/prepareRename
|
|
20
|
-
textDocument/foldingRange
|
|
21
|
-
textDocument/documentHighlight
|
|
22
|
-
workspace/symbol
|
|
23
|
-
]
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
class Initialized < Base
|
|
7
|
+
def process
|
|
8
|
+
# @todo Temporarily removed textDocument/codeAction
|
|
9
|
+
host.register_capabilities %w[
|
|
10
|
+
textDocument/completion
|
|
11
|
+
textDocument/hover
|
|
12
|
+
textDocument/signatureHelp
|
|
13
|
+
textDocument/formatting
|
|
14
|
+
textDocument/documentSymbol
|
|
15
|
+
textDocument/definition
|
|
16
|
+
textDocument/typeDefinition
|
|
17
|
+
textDocument/references
|
|
18
|
+
textDocument/rename
|
|
19
|
+
textDocument/prepareRename
|
|
20
|
+
textDocument/foldingRange
|
|
21
|
+
textDocument/documentHighlight
|
|
22
|
+
workspace/symbol
|
|
23
|
+
]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
module TextDocument
|
|
7
|
-
autoload :Base, 'solargraph/language_server/message/text_document/base'
|
|
8
|
-
autoload :Completion, 'solargraph/language_server/message/text_document/completion'
|
|
9
|
-
autoload :DidOpen, 'solargraph/language_server/message/text_document/did_open'
|
|
10
|
-
autoload :DidChange, 'solargraph/language_server/message/text_document/did_change'
|
|
11
|
-
autoload :DidClose, 'solargraph/language_server/message/text_document/did_close'
|
|
12
|
-
autoload :DidSave, 'solargraph/language_server/message/text_document/did_save'
|
|
13
|
-
autoload :Hover, 'solargraph/language_server/message/text_document/hover'
|
|
14
|
-
autoload :SignatureHelp, 'solargraph/language_server/message/text_document/signature_help'
|
|
15
|
-
autoload :OnTypeFormatting, 'solargraph/language_server/message/text_document/on_type_formatting'
|
|
16
|
-
autoload :Definition, 'solargraph/language_server/message/text_document/definition'
|
|
17
|
-
autoload :TypeDefinition, 'solargraph/language_server/message/text_document/type_definition'
|
|
18
|
-
autoload :DocumentSymbol, 'solargraph/language_server/message/text_document/document_symbol'
|
|
19
|
-
autoload :Formatting, 'solargraph/language_server/message/text_document/formatting'
|
|
20
|
-
autoload :References, 'solargraph/language_server/message/text_document/references'
|
|
21
|
-
autoload :Rename, 'solargraph/language_server/message/text_document/rename'
|
|
22
|
-
autoload :PrepareRename, 'solargraph/language_server/message/text_document/prepare_rename'
|
|
23
|
-
autoload :FoldingRange, 'solargraph/language_server/message/text_document/folding_range'
|
|
24
|
-
autoload :DocumentHighlight, 'solargraph/language_server/message/text_document/document_highlight'
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module TextDocument
|
|
7
|
+
autoload :Base, 'solargraph/language_server/message/text_document/base'
|
|
8
|
+
autoload :Completion, 'solargraph/language_server/message/text_document/completion'
|
|
9
|
+
autoload :DidOpen, 'solargraph/language_server/message/text_document/did_open'
|
|
10
|
+
autoload :DidChange, 'solargraph/language_server/message/text_document/did_change'
|
|
11
|
+
autoload :DidClose, 'solargraph/language_server/message/text_document/did_close'
|
|
12
|
+
autoload :DidSave, 'solargraph/language_server/message/text_document/did_save'
|
|
13
|
+
autoload :Hover, 'solargraph/language_server/message/text_document/hover'
|
|
14
|
+
autoload :SignatureHelp, 'solargraph/language_server/message/text_document/signature_help'
|
|
15
|
+
autoload :OnTypeFormatting, 'solargraph/language_server/message/text_document/on_type_formatting'
|
|
16
|
+
autoload :Definition, 'solargraph/language_server/message/text_document/definition'
|
|
17
|
+
autoload :TypeDefinition, 'solargraph/language_server/message/text_document/type_definition'
|
|
18
|
+
autoload :DocumentSymbol, 'solargraph/language_server/message/text_document/document_symbol'
|
|
19
|
+
autoload :Formatting, 'solargraph/language_server/message/text_document/formatting'
|
|
20
|
+
autoload :References, 'solargraph/language_server/message/text_document/references'
|
|
21
|
+
autoload :Rename, 'solargraph/language_server/message/text_document/rename'
|
|
22
|
+
autoload :PrepareRename, 'solargraph/language_server/message/text_document/prepare_rename'
|
|
23
|
+
autoload :FoldingRange, 'solargraph/language_server/message/text_document/folding_range'
|
|
24
|
+
autoload :DocumentHighlight, 'solargraph/language_server/message/text_document/document_highlight'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'securerandom'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
module LanguageServer
|
|
7
|
-
# Progress notification handling for language server hosts.
|
|
8
|
-
#
|
|
9
|
-
class Progress
|
|
10
|
-
WAITING = :waiting
|
|
11
|
-
CREATED = :created
|
|
12
|
-
FINISHED = :finished
|
|
13
|
-
|
|
14
|
-
# @return [String]
|
|
15
|
-
attr_reader :uuid
|
|
16
|
-
|
|
17
|
-
# @return [String]
|
|
18
|
-
attr_reader :title
|
|
19
|
-
|
|
20
|
-
# @return [String, nil]
|
|
21
|
-
attr_reader :kind
|
|
22
|
-
|
|
23
|
-
# @return [String, nil]
|
|
24
|
-
attr_reader :message
|
|
25
|
-
|
|
26
|
-
# @return [Integer]
|
|
27
|
-
attr_reader :percentage
|
|
28
|
-
|
|
29
|
-
# @return [Symbol]
|
|
30
|
-
attr_reader :status
|
|
31
|
-
|
|
32
|
-
# @param title [String]
|
|
33
|
-
def initialize title
|
|
34
|
-
@title = title
|
|
35
|
-
@uuid = SecureRandom.uuid
|
|
36
|
-
@percentage = 0
|
|
37
|
-
@status = WAITING
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# @param message [String]
|
|
41
|
-
# @param percentage [Integer]
|
|
42
|
-
# @return [void]
|
|
43
|
-
def begin message, percentage
|
|
44
|
-
@kind = 'begin'
|
|
45
|
-
@message = message
|
|
46
|
-
@percentage = percentage
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# @param message [String]
|
|
50
|
-
# @param percentage [Integer]
|
|
51
|
-
# @return [void]
|
|
52
|
-
def report message, percentage
|
|
53
|
-
@kind = 'report'
|
|
54
|
-
@message = message
|
|
55
|
-
@percentage = percentage
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# @param message [String]
|
|
59
|
-
# @return [void]
|
|
60
|
-
def finish message
|
|
61
|
-
@kind = 'end'
|
|
62
|
-
@message = message
|
|
63
|
-
@percentage = 100
|
|
64
|
-
true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# @param host [Solargraph::LanguageServer::Host]
|
|
68
|
-
# @return [void]
|
|
69
|
-
def send host
|
|
70
|
-
return unless host.client_supports_progress? && !finished?
|
|
71
|
-
|
|
72
|
-
message = build
|
|
73
|
-
create(host)
|
|
74
|
-
host.send_notification '$/progress', message
|
|
75
|
-
@status = FINISHED if kind == 'end'
|
|
76
|
-
keep_alive host
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def created?
|
|
80
|
-
[CREATED, FINISHED].include?(status)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def finished?
|
|
84
|
-
status == FINISHED
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
private
|
|
88
|
-
|
|
89
|
-
# @param host [Solargraph::LanguageServer::Host]
|
|
90
|
-
# @return [void]
|
|
91
|
-
def create host
|
|
92
|
-
return if created?
|
|
93
|
-
|
|
94
|
-
host.send_request 'window/workDoneProgress/create', { token: uuid }
|
|
95
|
-
@status = CREATED
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# @return [Hash]
|
|
99
|
-
def build
|
|
100
|
-
{
|
|
101
|
-
token: uuid,
|
|
102
|
-
value: {
|
|
103
|
-
kind: kind,
|
|
104
|
-
cancellable: false
|
|
105
|
-
}.merge(build_value)
|
|
106
|
-
}
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# @return [Hash]
|
|
110
|
-
def build_value
|
|
111
|
-
case kind
|
|
112
|
-
when 'begin'
|
|
113
|
-
{ title: title, message: message, percentage: percentage }
|
|
114
|
-
when 'report'
|
|
115
|
-
{ message: message, percentage: percentage }
|
|
116
|
-
when 'end'
|
|
117
|
-
{ message: message }
|
|
118
|
-
else
|
|
119
|
-
raise "Invalid progress kind #{kind}"
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# @param host [Host]
|
|
124
|
-
# @return [void]
|
|
125
|
-
def keep_alive host
|
|
126
|
-
mutex.synchronize { @last = Time.now }
|
|
127
|
-
@keep_alive ||= Thread.new do
|
|
128
|
-
until finished?
|
|
129
|
-
sleep 10
|
|
130
|
-
break if finished?
|
|
131
|
-
next if mutex.synchronize { Time.now - @last < 10 }
|
|
132
|
-
send host
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# @return [Thread::Mutex]
|
|
138
|
-
def mutex
|
|
139
|
-
@mutex ||= Mutex.new
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module LanguageServer
|
|
7
|
+
# Progress notification handling for language server hosts.
|
|
8
|
+
#
|
|
9
|
+
class Progress
|
|
10
|
+
WAITING = :waiting
|
|
11
|
+
CREATED = :created
|
|
12
|
+
FINISHED = :finished
|
|
13
|
+
|
|
14
|
+
# @return [String]
|
|
15
|
+
attr_reader :uuid
|
|
16
|
+
|
|
17
|
+
# @return [String]
|
|
18
|
+
attr_reader :title
|
|
19
|
+
|
|
20
|
+
# @return [String, nil]
|
|
21
|
+
attr_reader :kind
|
|
22
|
+
|
|
23
|
+
# @return [String, nil]
|
|
24
|
+
attr_reader :message
|
|
25
|
+
|
|
26
|
+
# @return [Integer]
|
|
27
|
+
attr_reader :percentage
|
|
28
|
+
|
|
29
|
+
# @return [Symbol]
|
|
30
|
+
attr_reader :status
|
|
31
|
+
|
|
32
|
+
# @param title [String]
|
|
33
|
+
def initialize title
|
|
34
|
+
@title = title
|
|
35
|
+
@uuid = SecureRandom.uuid
|
|
36
|
+
@percentage = 0
|
|
37
|
+
@status = WAITING
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @param message [String]
|
|
41
|
+
# @param percentage [Integer]
|
|
42
|
+
# @return [void]
|
|
43
|
+
def begin message, percentage
|
|
44
|
+
@kind = 'begin'
|
|
45
|
+
@message = message
|
|
46
|
+
@percentage = percentage
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @param message [String]
|
|
50
|
+
# @param percentage [Integer]
|
|
51
|
+
# @return [void]
|
|
52
|
+
def report message, percentage
|
|
53
|
+
@kind = 'report'
|
|
54
|
+
@message = message
|
|
55
|
+
@percentage = percentage
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @param message [String]
|
|
59
|
+
# @return [void]
|
|
60
|
+
def finish message
|
|
61
|
+
@kind = 'end'
|
|
62
|
+
@message = message
|
|
63
|
+
@percentage = 100
|
|
64
|
+
true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @param host [Solargraph::LanguageServer::Host]
|
|
68
|
+
# @return [void]
|
|
69
|
+
def send host
|
|
70
|
+
return unless host.client_supports_progress? && !finished?
|
|
71
|
+
|
|
72
|
+
message = build
|
|
73
|
+
create(host)
|
|
74
|
+
host.send_notification '$/progress', message
|
|
75
|
+
@status = FINISHED if kind == 'end'
|
|
76
|
+
keep_alive host
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def created?
|
|
80
|
+
[CREATED, FINISHED].include?(status)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def finished?
|
|
84
|
+
status == FINISHED
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# @param host [Solargraph::LanguageServer::Host]
|
|
90
|
+
# @return [void]
|
|
91
|
+
def create host
|
|
92
|
+
return if created?
|
|
93
|
+
|
|
94
|
+
host.send_request 'window/workDoneProgress/create', { token: uuid }
|
|
95
|
+
@status = CREATED
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# @return [Hash]
|
|
99
|
+
def build
|
|
100
|
+
{
|
|
101
|
+
token: uuid,
|
|
102
|
+
value: {
|
|
103
|
+
kind: kind,
|
|
104
|
+
cancellable: false
|
|
105
|
+
}.merge(build_value)
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# @return [Hash]
|
|
110
|
+
def build_value
|
|
111
|
+
case kind
|
|
112
|
+
when 'begin'
|
|
113
|
+
{ title: title, message: message, percentage: percentage }
|
|
114
|
+
when 'report'
|
|
115
|
+
{ message: message, percentage: percentage }
|
|
116
|
+
when 'end'
|
|
117
|
+
{ message: message }
|
|
118
|
+
else
|
|
119
|
+
raise "Invalid progress kind #{kind}"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# @param host [Host]
|
|
124
|
+
# @return [void]
|
|
125
|
+
def keep_alive host
|
|
126
|
+
mutex.synchronize { @last = Time.now }
|
|
127
|
+
@keep_alive ||= Thread.new do
|
|
128
|
+
until finished?
|
|
129
|
+
sleep 10
|
|
130
|
+
break if finished?
|
|
131
|
+
next if mutex.synchronize { Time.now - @last < 10 }
|
|
132
|
+
send host
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# @return [Thread::Mutex]
|
|
138
|
+
def mutex
|
|
139
|
+
@mutex ||= Mutex.new
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|