@@ -52,40 +52,45 @@ export class LanguageServerManager implements ILanguageServerManager {
5252 this . _configuration = configuration ;
5353 }
5454
55+ protected _comparePriorities ( a : TLanguageServerId , b : TLanguageServerId ) {
56+ const DEFAULT_PRIORITY = 50 ;
57+ const a_priority = this . _configuration [ a ] ?. priority ?? DEFAULT_PRIORITY ;
58+ const b_priority = this . _configuration [ b ] ?. priority ?? DEFAULT_PRIORITY ;
59+ if ( a_priority == b_priority ) {
60+ this . console . warn (
61+ `Two matching servers: ${ a } and ${ b } have the same priority; choose which one to use by changing the priority in Advanced Settings Editor`
62+ ) ;
63+ return a . localeCompare ( b ) ;
64+ }
65+ // higher priority = higher in the list (descending order)
66+ return b_priority - a_priority ;
67+ }
68+
5569 getMatchingServers ( options : ILanguageServerManager . IGetServerIdOptions ) {
70+ if ( ! options . language ) {
71+ this . console . error (
72+ 'Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type'
73+ ) ;
74+ return [ ] ;
75+ }
76+
5677 const matchingSessionsKeys : TLanguageServerId [ ] = [ ] ;
57- const config = this . _configuration ;
78+ const lowerCaseLanguage = options . language . toLocaleLowerCase ( ) ;
5879
5980 // most things speak language
6081 // if language is not known, it is guessed based on MIME type earlier
6182 // so some language should be available by now (which can be not obvious, e.g. "plain" for txt documents)
6283 for ( const [ key , session ] of this . _sessions . entries ( ) ) {
63- if ( options . language ) {
64- if (
65- session . spec . languages . indexOf (
66- options . language . toLocaleLowerCase ( )
67- ) !== - 1
68- ) {
69- matchingSessionsKeys . push ( key ) ;
70- }
71- } else {
72- this . console . error (
73- 'Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type'
74- ) ;
84+ if (
85+ session . spec . languages . some (
86+ language => language . toLocaleLowerCase ( ) == lowerCaseLanguage
87+ )
88+ ) {
89+ matchingSessionsKeys . push ( key ) ;
7590 }
7691 }
7792
78- return matchingSessionsKeys . sort ( ( a , b ) => {
79- const a_priority = config [ a ] ?. priority ?? 50 ;
80- const b_priority = config [ b ] ?. priority ?? 50 ;
81- if ( a_priority == b_priority ) {
82- this . console . warn (
83- `Two matching servers: ${ a } and ${ b } have the same priority; choose which one to use by changing the priority in Advanced Settings Editor`
84- ) ;
85- }
86- // higher priority = higher in the list (descending order)
87- return b_priority - a_priority ;
88- } ) ;
93+ return matchingSessionsKeys . sort ( this . _comparePriorities ) ;
8994 }
9095
9196 get statusCode ( ) : number {
0 commit comments