@@ -156,45 +156,22 @@ function collectClientOptions(
156
156
const supportedSchemes = [ "file" , "git" ] ;
157
157
158
158
const fsPath = workspaceFolder . uri . fsPath . replace ( / \/ $ / , "" ) ;
159
+ const pathConverter = ruby . pathConverter ;
159
160
160
161
// For each workspace, the language client is responsible for handling requests for:
161
162
// 1. Files inside of the workspace itself
162
163
// 2. Bundled gems
163
164
// 3. Default gems
164
165
let documentSelector : DocumentSelector = SUPPORTED_LANGUAGE_IDS . flatMap (
165
166
( language ) => {
166
- return supportedSchemes . map ( ( scheme ) => {
167
- return { scheme, language, pattern : `${ fsPath } /**/*` } ;
167
+ return pathConverter . alternativePaths ( fsPath ) . flatMap ( ( pathVariant ) => {
168
+ return supportedSchemes . map ( ( scheme ) => {
169
+ return { scheme, language, pattern : `${ pathVariant } /**/*` } ;
170
+ } ) ;
168
171
} ) ;
169
172
} ,
170
173
) ;
171
174
172
- const pathConverter = ruby . pathConverter ;
173
-
174
- const pushAlternativePaths = (
175
- path : string ,
176
- schemes : string [ ] = supportedSchemes ,
177
- ) => {
178
- schemes . forEach ( ( scheme ) => {
179
- [
180
- pathConverter . toLocalPath ( path ) ,
181
- pathConverter . toRemotePath ( path ) ,
182
- ] . forEach ( ( convertedPath ) => {
183
- if ( convertedPath !== path ) {
184
- SUPPORTED_LANGUAGE_IDS . forEach ( ( language ) => {
185
- documentSelector . push ( {
186
- scheme,
187
- language,
188
- pattern : `${ convertedPath } /**/*` ,
189
- } ) ;
190
- } ) ;
191
- }
192
- } ) ;
193
- } ) ;
194
- } ;
195
-
196
- pushAlternativePaths ( fsPath ) ;
197
-
198
175
// Only the first language server we spawn should handle unsaved files, otherwise requests will be duplicated across
199
176
// all workspaces
200
177
if ( isMainWorkspace ) {
@@ -208,37 +185,35 @@ function collectClientOptions(
208
185
209
186
ruby . gemPath . forEach ( ( gemPath ) => {
210
187
supportedSchemes . forEach ( ( scheme ) => {
211
- documentSelector . push ( {
212
- scheme,
213
- language : "ruby" ,
214
- pattern : `${ gemPath } /**/*` ,
215
- } ) ;
216
-
217
- pushAlternativePaths ( gemPath , [ scheme ] ) ;
218
-
219
- // Because of how default gems are installed, the gemPath location is actually not exactly where the files are
220
- // located. With the regex, we are correcting the default gem path from this (where the files are not located)
221
- // /opt/rubies/3.3.1/lib/ruby/gems/3.3.0
222
- //
223
- // to this (where the files are actually stored)
224
- // /opt/rubies/3.3.1/lib/ruby/3.3.0
225
- //
226
- // Notice that we still need to add the regular path to the selector because some version managers will install
227
- // gems under the non-corrected path
228
- if ( / l i b \/ r u b y \/ g e m s \/ (? = \d ) / . test ( gemPath ) ) {
229
- const correctedPath = gemPath . replace (
230
- / l i b \/ r u b y \/ g e m s \/ (? = \d ) / ,
231
- "lib/ruby/" ,
232
- ) ;
233
-
188
+ pathConverter . alternativePaths ( gemPath ) . forEach ( ( pathVariant ) => {
234
189
documentSelector . push ( {
235
190
scheme,
236
191
language : "ruby" ,
237
- pattern : `${ correctedPath } /**/*` ,
192
+ pattern : `${ pathVariant } /**/*` ,
238
193
} ) ;
239
194
240
- pushAlternativePaths ( correctedPath , [ scheme ] ) ;
241
- }
195
+ // Because of how default gems are installed, the gemPath location is actually not exactly where the files are
196
+ // located. With the regex, we are correcting the default gem path from this (where the files are not located)
197
+ // /opt/rubies/3.3.1/lib/ruby/gems/3.3.0
198
+ //
199
+ // to this (where the files are actually stored)
200
+ // /opt/rubies/3.3.1/lib/ruby/3.3.0
201
+ //
202
+ // Notice that we still need to add the regular path to the selector because some version managers will install
203
+ // gems under the non-corrected path
204
+ if ( / l i b \/ r u b y \/ g e m s \/ (? = \d ) / . test ( pathVariant ) ) {
205
+ const correctedPath = pathVariant . replace (
206
+ / l i b \/ r u b y \/ g e m s \/ (? = \d ) / ,
207
+ "lib/ruby/" ,
208
+ ) ;
209
+
210
+ documentSelector . push ( {
211
+ scheme,
212
+ language : "ruby" ,
213
+ pattern : `${ correctedPath } /**/*` ,
214
+ } ) ;
215
+ }
216
+ } ) ;
242
217
} ) ;
243
218
} ) ;
244
219
0 commit comments