sorbet_view 0.15.1 → 0.16.0
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/README.md +1 -1
- data/lib/sorbet_view/configuration.rb +1 -1
- data/lib/sorbet_view/lsp/server.rb +22 -0
- data/lib/sorbet_view/lsp/uri_mapper.rb +17 -14
- data/lib/sorbet_view/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f936199a1cad03c79f83da8a6949baf4070f0df8e7d901c63c9164b8c87aaa6d
|
|
4
|
+
data.tar.gz: 26b629843c5b29be942e93d164d4fbc1091384fea028647ff55a0b8eb09d7ba8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f5d329c29b9c205b8c3cd19ae2e4ad7e9aaea6d2f7c73e6d086fe589936a627fa4d587da8d4dc29fc63aa80926b69be211c5092e2fbd4c5f9e6362e5e50503fc
|
|
7
|
+
data.tar.gz: d024285a5c46fc66225502eed7cd7993de8d37ed41fbb6359626047ec463c57a99a6092b3f4995917f7e38551716c45fd7227fe4009191c3ff963a6caf183d7b
|
data/README.md
CHANGED
|
@@ -61,7 +61,7 @@ skip_missing_locals: true
|
|
|
61
61
|
| `typed_level` | `'true'` | Sorbet `typed` level for generated files |
|
|
62
62
|
| `component_dirs` | `[]` | Directories to scan for ViewComponent files |
|
|
63
63
|
| `controller_dirs` | `['app/controllers']` | Controller directories to watch for changes (LSP recompiles associated templates) |
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
| `sorbet_options` | `[]` | Additional options passed to Sorbet |
|
|
66
66
|
|
|
67
67
|
## Usage
|
|
@@ -13,7 +13,7 @@ module SorbetView
|
|
|
13
13
|
const :skip_missing_locals, T::Boolean, default: true
|
|
14
14
|
const :sorbet_path, String, default: 'srb'
|
|
15
15
|
const :typed_level, String, default: 'true'
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
const :component_dirs, T::Array[String], default: []
|
|
18
18
|
const :controller_dirs, T::Array[String], default: ['app/controllers']
|
|
19
19
|
const :sorbet_options, T::Array[String], default: []
|
|
@@ -99,6 +99,9 @@ module SorbetView
|
|
|
99
99
|
|
|
100
100
|
sig { params(message: T::Hash[String, T.untyped]).void }
|
|
101
101
|
def handle_initialize(message)
|
|
102
|
+
# Auto-detect path mapping from editor's rootUri
|
|
103
|
+
detect_root_mapping(message['params'])
|
|
104
|
+
|
|
102
105
|
# Compile all templates first
|
|
103
106
|
compile_all_templates
|
|
104
107
|
|
|
@@ -141,6 +144,25 @@ module SorbetView
|
|
|
141
144
|
@transport.send_response(message['id'], nil)
|
|
142
145
|
end
|
|
143
146
|
|
|
147
|
+
sig { params(params: T.nilable(T::Hash[String, T.untyped])).void }
|
|
148
|
+
def detect_root_mapping(params)
|
|
149
|
+
return unless params
|
|
150
|
+
|
|
151
|
+
root_uri = params['rootUri'] || params['rootPath']
|
|
152
|
+
return unless root_uri
|
|
153
|
+
|
|
154
|
+
editor_root = if root_uri.start_with?('file://')
|
|
155
|
+
URI.decode_www_form_component(URI.parse(root_uri).path || '')
|
|
156
|
+
else
|
|
157
|
+
root_uri
|
|
158
|
+
end
|
|
159
|
+
return if editor_root.empty?
|
|
160
|
+
|
|
161
|
+
local_root = Dir.pwd
|
|
162
|
+
@uri_mapper.set_roots(editor_root: editor_root, local_root: local_root)
|
|
163
|
+
@logger.info("Root mapping: editor=#{editor_root} local=#{local_root}")
|
|
164
|
+
end
|
|
165
|
+
|
|
144
166
|
# --- Document Sync ---
|
|
145
167
|
|
|
146
168
|
sig { params(message: T::Hash[String, T.untyped]).void }
|
|
@@ -14,8 +14,17 @@ module SorbetView
|
|
|
14
14
|
sig { params(config: Configuration).void }
|
|
15
15
|
def initialize(config:)
|
|
16
16
|
@output_dir = config.output_dir
|
|
17
|
-
|
|
18
|
-
@
|
|
17
|
+
@editor_root = T.let(nil, T.nilable(String))
|
|
18
|
+
@local_root = T.let(nil, T.nilable(String))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Auto-detect path mapping from LSP rootUri vs local working directory.
|
|
22
|
+
sig { params(editor_root: String, local_root: String).void }
|
|
23
|
+
def set_roots(editor_root:, local_root:)
|
|
24
|
+
return if editor_root == local_root
|
|
25
|
+
|
|
26
|
+
@editor_root = editor_root
|
|
27
|
+
@local_root = local_root
|
|
19
28
|
end
|
|
20
29
|
|
|
21
30
|
sig { params(uri: String).returns(T::Boolean) }
|
|
@@ -73,12 +82,9 @@ module SorbetView
|
|
|
73
82
|
else
|
|
74
83
|
uri
|
|
75
84
|
end
|
|
76
|
-
# Map
|
|
77
|
-
@
|
|
78
|
-
|
|
79
|
-
path = path.sub(from, to)
|
|
80
|
-
break
|
|
81
|
-
end
|
|
85
|
+
# Map editor root -> local root
|
|
86
|
+
if @editor_root && @local_root && path.start_with?(@editor_root)
|
|
87
|
+
path = path.sub(@editor_root, @local_root)
|
|
82
88
|
end
|
|
83
89
|
# Make relative to CWD
|
|
84
90
|
cwd = Dir.pwd
|
|
@@ -91,12 +97,9 @@ module SorbetView
|
|
|
91
97
|
sig { params(path: String).returns(String) }
|
|
92
98
|
def path_to_uri(path)
|
|
93
99
|
absolute = File.expand_path(path)
|
|
94
|
-
# Map local
|
|
95
|
-
@
|
|
96
|
-
|
|
97
|
-
absolute = absolute.sub(to, from)
|
|
98
|
-
break
|
|
99
|
-
end
|
|
100
|
+
# Map local root -> editor root
|
|
101
|
+
if @editor_root && @local_root && absolute.start_with?(@local_root)
|
|
102
|
+
absolute = absolute.sub(@local_root, @editor_root)
|
|
100
103
|
end
|
|
101
104
|
"file://#{URI.encode_www_form_component(absolute).gsub('%2F', '/')}"
|
|
102
105
|
end
|
data/lib/sorbet_view/version.rb
CHANGED