31
31
import com .redhat .devtools .lsp4ij .internal .StringUtils ;
32
32
import com .redhat .devtools .lsp4ij .launching .ServerMappingSettings ;
33
33
import com .redhat .devtools .lsp4ij .launching .UserDefinedLanguageServerSettings ;
34
- import com .redhat .devtools .lsp4ij .server .definition .LanguageServerDefinition ;
35
- import com .redhat .devtools .lsp4ij .server .definition .LanguageServerDefinitionListener ;
36
- import com .redhat .devtools .lsp4ij .server .definition .LanguageServerFileAssociation ;
37
- import com .redhat .devtools .lsp4ij .server .definition .ServerFileNamePatternMapping ;
38
- import com .redhat .devtools .lsp4ij .server .definition .ServerFileTypeMapping ;
39
- import com .redhat .devtools .lsp4ij .server .definition .ServerLanguageMapping ;
40
- import com .redhat .devtools .lsp4ij .server .definition .ServerMapping ;
41
- import com .redhat .devtools .lsp4ij .server .definition .extension .ExtensionLanguageServerDefinition ;
42
- import com .redhat .devtools .lsp4ij .server .definition .extension .FileNamePatternMappingExtensionPointBean ;
43
- import com .redhat .devtools .lsp4ij .server .definition .extension .FileTypeMappingExtensionPointBean ;
44
- import com .redhat .devtools .lsp4ij .server .definition .extension .LanguageMappingExtensionPointBean ;
45
- import com .redhat .devtools .lsp4ij .server .definition .extension .SemanticTokensColorsProviderExtensionPointBean ;
46
- import com .redhat .devtools .lsp4ij .server .definition .extension .ServerExtensionPointBean ;
34
+ import com .redhat .devtools .lsp4ij .server .definition .*;
35
+ import com .redhat .devtools .lsp4ij .server .definition .extension .*;
47
36
import com .redhat .devtools .lsp4ij .server .definition .launching .UserDefinedLanguageServerDefinition ;
48
37
import com .redhat .devtools .lsp4ij .usages .LSPFindUsagesProvider ;
49
38
import org .jetbrains .annotations .ApiStatus ;
@@ -286,13 +275,13 @@ private static String getServerNotAvailableMessage(ServerMapping mapping) {
286
275
/**
287
276
* @param language the language
288
277
* @param fileType the file type.
289
- * @param file
278
+ * @param fileName the file name
290
279
* @return the {@link LanguageServerDefinition}s <strong>directly</strong> associated to the given content-type.
291
280
* This does <strong>not</strong> include the one that match transitively as per content-type hierarchy
292
281
*/
293
- List <LanguageServerFileAssociation > findLanguageServerDefinitionFor (final @ Nullable Language language , @ Nullable FileType fileType , @ NotNull VirtualFile file ) {
282
+ List <LanguageServerFileAssociation > findLanguageServerDefinitionFor (final @ Nullable Language language , @ Nullable FileType fileType , @ NotNull String fileName ) {
294
283
return fileAssociations .stream ()
295
- .filter (mapping -> mapping .match (language , fileType , file . getName () ))
284
+ .filter (mapping -> mapping .match (language , fileType , fileName ))
296
285
.collect (Collectors .toList ());
297
286
}
298
287
@@ -475,7 +464,7 @@ private void removeAssociationsFor(LanguageServerDefinition definition) {
475
464
settings .setMappings (request .mappings ());
476
465
477
466
if (nameChanged || commandChanged || userEnvironmentVariablesChanged || includeSystemEnvironmentVariablesChanged ||
478
- mappingsChanged || configurationContentChanged || initializationOptionsContentChanged ) {
467
+ mappingsChanged || configurationContentChanged || initializationOptionsContentChanged ) {
479
468
// Notifications
480
469
LanguageServerDefinitionListener .LanguageServerChangedEvent event = new LanguageServerDefinitionListener .LanguageServerChangedEvent (
481
470
request .project (),
@@ -523,7 +512,9 @@ public boolean isFileSupported(@Nullable PsiFile file) {
523
512
if (file == null ) {
524
513
return false ;
525
514
}
526
- return isFileSupported (file .getVirtualFile (), file .getProject ());
515
+ Language language = file .getLanguage ();
516
+ FileType fileType = file .getFileType ();
517
+ return isFileSupported (language , fileType , file .getName (), null , file , file .getProject ());
527
518
}
528
519
529
520
/**
@@ -539,15 +530,25 @@ public boolean isFileSupported(@Nullable VirtualFile file, @NotNull Project proj
539
530
}
540
531
Language language = LSPIJUtils .getFileLanguage (file , project );
541
532
FileType fileType = file .getFileType ();
533
+ return isFileSupported (language , fileType , file .getName (), file , null , project );
534
+ }
535
+
536
+ private boolean isFileSupported (@ Nullable Language language ,
537
+ @ Nullable FileType fileType ,
538
+ @ NotNull String filename ,
539
+ @ Nullable VirtualFile file ,
540
+ @ Nullable PsiFile psiFile ,
541
+ @ NotNull Project project ) {
542
542
if (fileAssociations
543
543
.stream ()
544
- .anyMatch (mapping -> mapping .match (language , fileType , file .getName ()))) {
545
- if (!file .isInLocalFileSystem ()) {
546
- if (file instanceof LightVirtualFile ) {
544
+ .anyMatch (mapping -> mapping .match (language , fileType , filename ))) {
545
+ VirtualFile f = file != null ? file : psiFile .getVirtualFile ();
546
+ if (!f .isInLocalFileSystem ()) {
547
+ if (f instanceof LightVirtualFile ) {
547
548
return false ;
548
549
}
549
- PsiFile psiFile = LSPIJUtils .getPsiFile (file , project );
550
- if (psiFile != null && !psiFile .isPhysical ()) {
550
+ PsiFile pf = psiFile != null ? psiFile : LSPIJUtils .getPsiFile (file , project );
551
+ if (pf != null && !pf .isPhysical ()) {
551
552
return false ;
552
553
}
553
554
}
0 commit comments