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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80eae84dbfd807302e09be6c4564c552f68d7a22d05928594a29fbeb184c736d
4
- data.tar.gz: dfcba4a33f1d8cd9a4eb4bcace9cede236afc442e6e0e0d1da59f0b2ddcc66c9
3
+ metadata.gz: f936199a1cad03c79f83da8a6949baf4070f0df8e7d901c63c9164b8c87aaa6d
4
+ data.tar.gz: 26b629843c5b29be942e93d164d4fbc1091384fea028647ff55a0b8eb09d7ba8
5
5
  SHA512:
6
- metadata.gz: 8bea55f1111b1961d0b82b651edda9c8fb279cd48d2c3724592a635285e90b28c5da56dfc86e5120ce4ce41f0d4914df215d9da40f711c545c1fc39e06adb01f
7
- data.tar.gz: 826d349d6659d09ba24bc85a1d627a7eac451e52138f4279e2c627fcfd2b114348dcf532a359bddbe00d7c06429fc7cbf03b2a8dab184294883de7071443b18a
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
- | `path_mapping` | `{}` | Path mapping for remote development (e.g., Docker) |
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
- const :path_mapping, T::Hash[String, String], default: {}
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
- # path_mapping: { "/host/path" => "/container/path" }
18
- @path_mapping = T.let(config.path_mapping, T::Hash[String, String])
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 host path -> local (container) path
77
- @path_mapping.each do |from, to|
78
- if path.start_with?(from)
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 (container) path -> host path
95
- @path_mapping.each do |from, to|
96
- if absolute.start_with?(to)
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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module SorbetView
5
- VERSION = '0.15.1'
5
+ VERSION = '0.16.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuma