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