klenod-lsp 0.0.31 → 0.0.32
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/lib/klenod/lsp/languages/haml/classes.rb +5 -3
- data/lib/klenod/lsp/languages/haml/props.rb +5 -1
- data/lib/klenod/lsp/languages/haml/rename.rb +7 -3
- data/lib/klenod/lsp/languages/haml.rb +10 -1
- data/lib/klenod/lsp/languages/imports.rb +10 -2
- data/lib/klenod/lsp/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f41f8fc46c0ec27d4ac70f84f6e60f9d3ad44f9fb50fafe7b4c13d71f935e071
|
|
4
|
+
data.tar.gz: 418a82a7691f2f70927806291379740e789d14795aa6e3afe8e2dbbee1825a74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3bfa7e60f2ca9e16b1aa01398a3ef1f44cca62907436cb120e313b3fc79a9fb959f0e560f1a51a4dcc47021371de999a1a4d24755df517e658066815218a3822
|
|
7
|
+
data.tar.gz: 2bd0c26fe1062883602fc4ff9f91d17730e6327f40c9f33e0cc739833a313cb03a5384724faf88e459e57605809e2e73ff051270ba06ece03bdf60d94b871b77
|
|
@@ -22,7 +22,7 @@ module Klenod
|
|
|
22
22
|
SHORTHAND_PREFIX = /\A\s*(?:%[A-Za-z][\w:-]*)?(?:[.#][\w-]+)*\.(?<partial>[\w-]*)\z/
|
|
23
23
|
LOOKUP_PREFIX = /ClassNames\[:(?<partial>[\w-]*)\z/
|
|
24
24
|
STYLE_KINDS = %i[companion_style inline_style].freeze
|
|
25
|
-
FILTER_HEAD = /\A\s
|
|
25
|
+
FILTER_HEAD = /\A\s*:(?<name>\w+)/
|
|
26
26
|
|
|
27
27
|
Occurrence = Data.define(:name, :span)
|
|
28
28
|
Definition = Data.define(:module_id, :generated)
|
|
@@ -92,14 +92,16 @@ module Klenod
|
|
|
92
92
|
# Indexes of the lines inside filters: every line after a `:name`
|
|
93
93
|
# line that is blank or indented deeper than it, as Haml reads them.
|
|
94
94
|
# Indentation alone also works while the document does not parse.
|
|
95
|
-
|
|
95
|
+
# Filters named in `except` are left out.
|
|
96
|
+
def filter_body_lines(lines, except: [])
|
|
96
97
|
filter_indent = nil
|
|
97
98
|
lines.each_with_index.with_object(Set.new) do |(line_text, index), body|
|
|
98
99
|
indent = line_text[/\A\s*/].length
|
|
99
100
|
if filter_indent && (line_text.strip.empty? || indent > filter_indent)
|
|
100
101
|
body << index
|
|
101
102
|
else
|
|
102
|
-
|
|
103
|
+
head = FILTER_HEAD.match(line_text)
|
|
104
|
+
filter_indent = (head && !except.include?(head[:name])) ? indent : nil
|
|
103
105
|
end
|
|
104
106
|
end
|
|
105
107
|
end
|
|
@@ -5,6 +5,7 @@ require "language_server-protocol"
|
|
|
5
5
|
|
|
6
6
|
require_relative "../../text"
|
|
7
7
|
require_relative "../imports"
|
|
8
|
+
require_relative "classes"
|
|
8
9
|
require_relative "ruby_regions"
|
|
9
10
|
|
|
10
11
|
module Klenod
|
|
@@ -42,10 +43,13 @@ module Klenod
|
|
|
42
43
|
|
|
43
44
|
def diagnostics(analysis, workspace, index)
|
|
44
45
|
lines = analysis.lines
|
|
45
|
-
bindings =
|
|
46
|
+
bindings = Haml.bindings(lines)
|
|
46
47
|
props_cache = {}
|
|
48
|
+
filter_body = Classes.filter_body_lines(lines)
|
|
47
49
|
|
|
48
50
|
lines.each_with_index.flat_map do |line_text, line_index|
|
|
51
|
+
next [] if filter_body.include?(line_index)
|
|
52
|
+
|
|
49
53
|
tag = TAG_LINE.match(line_text)
|
|
50
54
|
next [] unless tag
|
|
51
55
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../../text"
|
|
4
4
|
require_relative "../imports"
|
|
5
|
+
require_relative "classes"
|
|
5
6
|
require_relative "ruby_regions"
|
|
6
7
|
|
|
7
8
|
module Klenod
|
|
@@ -9,9 +10,9 @@ module Klenod
|
|
|
9
10
|
module Languages
|
|
10
11
|
class Haml
|
|
11
12
|
# Where a bound constant appears in a Haml document: the `%Name` tags
|
|
12
|
-
# and the whole-word uses inside Ruby, meaning `:ruby`
|
|
13
|
-
# lines, tag attributes, and printed tag content.
|
|
14
|
-
# its words.
|
|
13
|
+
# outside filters and the whole-word uses inside Ruby, meaning `:ruby`
|
|
14
|
+
# filters, script lines, tag attributes, and printed tag content.
|
|
15
|
+
# Plain text keeps its words.
|
|
15
16
|
module Rename
|
|
16
17
|
module_function
|
|
17
18
|
|
|
@@ -25,7 +26,10 @@ module Klenod
|
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
29
|
+
filter_body = Classes.filter_body_lines(lines)
|
|
28
30
|
lines.each_with_index do |line_text, index|
|
|
31
|
+
next if filter_body.include?(index)
|
|
32
|
+
|
|
29
33
|
Text.each_match(line_text, index, Haml::COMPONENT_TAG, group: :name) do |match, span|
|
|
30
34
|
next unless match[:name].split("::").first == name
|
|
31
35
|
|
|
@@ -68,13 +68,22 @@ module Klenod
|
|
|
68
68
|
|
|
69
69
|
# `%Details` compiles to the constant `Details`, bound by an import in
|
|
70
70
|
# the leading `:ruby` filter such as `Details = import("/components/Details")`.
|
|
71
|
+
# Imports in other filters, such as code samples in `:markdown`, are
|
|
72
|
+
# text.
|
|
71
73
|
def self.bindings(lines)
|
|
72
|
-
|
|
74
|
+
text = Classes.filter_body_lines(lines, except: %w[ruby])
|
|
75
|
+
Imports.bindings(lines.reject.with_index { |_line_text, index| text.include?(index) })
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def bindings(lines)
|
|
79
|
+
self.class.bindings(lines)
|
|
73
80
|
end
|
|
74
81
|
|
|
75
82
|
private
|
|
76
83
|
|
|
77
84
|
def component_target_at(line_text, position, lines)
|
|
85
|
+
return nil if Classes.filter_body_lines(lines).include?(position.line)
|
|
86
|
+
|
|
78
87
|
Text.each_match(line_text, position.line, COMPONENT_TAG, group: :name) do |match, span|
|
|
79
88
|
next unless span.include?(position)
|
|
80
89
|
|
|
@@ -218,6 +218,11 @@ module Klenod
|
|
|
218
218
|
Syntax::Ruby
|
|
219
219
|
end
|
|
220
220
|
|
|
221
|
+
# Constant names bound to imports in a document, keyed by name.
|
|
222
|
+
def bindings(lines)
|
|
223
|
+
Imports.bindings(lines)
|
|
224
|
+
end
|
|
225
|
+
|
|
221
226
|
def definition(analysis, position, workspace, _index = nil)
|
|
222
227
|
target = target_at(analysis, position)
|
|
223
228
|
module_id = target && Imports.resolve(target, analysis, workspace)
|
|
@@ -376,11 +381,14 @@ module Klenod
|
|
|
376
381
|
def usage_spans(importer_id, lines, specifiers)
|
|
377
382
|
return [] unless importer_id.extname == ".haml"
|
|
378
383
|
|
|
379
|
-
names =
|
|
384
|
+
names = Languages::Haml.bindings(lines).select { |_name, specifier| specifiers.include?(specifier) }.keys
|
|
380
385
|
return [] if names.empty?
|
|
381
386
|
|
|
382
387
|
spans = []
|
|
388
|
+
filter_body = Languages::Haml::Classes.filter_body_lines(lines)
|
|
383
389
|
lines.each_with_index do |line_text, index|
|
|
390
|
+
next if filter_body.include?(index)
|
|
391
|
+
|
|
384
392
|
Text.each_match(line_text, index, Languages::Haml::COMPONENT_TAG, group: :name) do |match, span|
|
|
385
393
|
spans << span if names.include?(match[:name].split("::").first)
|
|
386
394
|
end
|
|
@@ -391,7 +399,7 @@ module Klenod
|
|
|
391
399
|
# Bindings whose constant is never used in the file. Languages give
|
|
392
400
|
# the spans a constant occupies, the binding included.
|
|
393
401
|
def unused_binding_diagnostics(analysis)
|
|
394
|
-
|
|
402
|
+
bindings(analysis.lines).filter_map do |name, _specifier|
|
|
395
403
|
spans = rename_spans(analysis, name)
|
|
396
404
|
next if spans.length > 1
|
|
397
405
|
|
data/lib/klenod/lsp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-lsp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.32
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.32
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.32
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: language_server-protocol
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|