Skip to content

Commit f593c4a

Browse files
committed
LSP: Allow globs in GetProjectRootFiles
Some languages name the project description file after the root directory. I.e. `foo/foo.csproj` and `foo/foo.sln` in case of C#. This accomodates those language servers.
1 parent 22a5c84 commit f593c4a

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

ycmd/completers/language_server/language_server_completer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.
1717

1818
from functools import partial
19+
from pathlib import Path
1920
import abc
2021
import collections
2122
import contextlib
@@ -2306,8 +2307,8 @@ def _PurgeFileFromServer( self, file_path ):
23062307

23072308

23082309
def GetProjectRootFiles( self ):
2309-
"""Returns a list of files that indicate the root of the project.
2310-
It should be easier to override just this method than the whole
2310+
"""Returns a list of globs matching files that indicate the root of the
2311+
project. It should be easier to override just this method than the whole
23112312
GetProjectDirectory."""
23122313
return []
23132314

@@ -2362,7 +2363,7 @@ def GetWorkspaceForFilepath( self, filepath, strict = False ):
23622363
if project_root_files:
23632364
for folder in utils.PathsToAllParentFolders( filepath ):
23642365
for root_file in project_root_files:
2365-
if os.path.isfile( os.path.join( folder, root_file ) ):
2366+
if next( Path( folder ).glob( root_file ), [] ):
23662367
return folder
23672368
return None if strict else os.path.dirname( filepath )
23682369

ycmd/tests/language_server/generic_completer_test.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,62 @@ def test_GenericLSPCompleter_HoverIsList( self, app, *args ):
480480

481481

482482

483+
@IsolatedYcmd( { 'language_server':
484+
[ { 'name': 'foo',
485+
'filetypes': [ 'foo' ],
486+
'project_root_files': [ '*root' ],
487+
'cmdline': [ 'node', PATH_TO_GENERIC_COMPLETER, '--stdio' ] } ] } )
488+
def test_GenericLSPCompleter_DebugInfo_CustomRootGlob( self, app, *args ):
489+
test_file = PathToTestFile(
490+
'generic_server', 'foo', 'bar', 'baz', 'test_file' )
491+
request = BuildRequest( filepath = test_file,
492+
filetype = 'foo',
493+
line_num = 1,
494+
column_num = 1,
495+
contents = '',
496+
event_name = 'FileReadyToParse' )
497+
498+
app.post_json( '/event_notification', request )
499+
WaitUntilCompleterServerReady( app, 'foo' )
500+
request.pop( 'event_name' )
501+
response = app.post_json( '/debug_info', request ).json
502+
assert_that(
503+
response,
504+
has_entry( 'completer', has_entries( {
505+
'name': 'GenericLSP',
506+
'servers': contains_exactly( has_entries( {
507+
'name': 'fooCompleter',
508+
'is_running': instance_of( bool ),
509+
'executable': contains_exactly( instance_of( str ),
510+
instance_of( str ),
511+
instance_of( str ) ),
512+
'address': None,
513+
'port': None,
514+
'pid': instance_of( int ),
515+
'logfiles': contains_exactly( instance_of( str ) ),
516+
'extras': contains_exactly(
517+
has_entries( {
518+
'key': 'Server State',
519+
'value': instance_of( str ),
520+
} ),
521+
has_entries( {
522+
'key': 'Project Directory',
523+
'value': PathToTestFile( 'generic_server', 'foo' ),
524+
} ),
525+
has_entries( {
526+
'key': 'Open Workspaces',
527+
'value': has_items(),
528+
} ),
529+
has_entries( {
530+
'key': 'Settings',
531+
'value': '{}'
532+
} ),
533+
)
534+
} ) ),
535+
} ) )
536+
)
537+
538+
483539
@IsolatedYcmd( { 'language_server':
484540
[ { 'name': 'foo',
485541
'filetypes': [ 'foo' ],

0 commit comments

Comments
 (0)