forked from ycm-core/ycmd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
php_completer.py
90 lines (68 loc) · 2.49 KB
/
php_completer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2018 ycmd contributors
#
# This file is part of ycmd.
#
# ycmd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ycmd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
# Not installing aliases from python-future; it's unreliable and slow.
from builtins import * # noqa
from ycmd.completers.language_server import (
simple_language_server_completer as slsc )
from ycmd import responses, utils
from ycmd.utils import LOGGER
import os
PATH_TO_SERVER = os.path.abspath(
os.path.join(
os.path.dirname( __file__ ),
'..',
'..',
'..',
'third_party',
'php-language-server-runtime',
'vendor',
'bin',
'php-language-server.php' ) )
PATH_TO_PHP = utils.PathToFirstExistingExecutable( [ 'php' ] )
def ShouldEnablePHPCompleter():
if not os.path.exists( PATH_TO_SERVER ):
LOGGER.info( "Not using PHP completer: not installed" )
return False
if not PATH_TO_PHP:
LOGGER.warn( "Unable to start PHP completer: can't find PHP" )
return False
LOGGER.info( "PHP completer is ready to use" )
return True
class PHPCompleter( slsc.SimpleLSPCompleter ):
def __init__( self, user_options ):
super( PHPCompleter, self ).__init__( user_options )
def GetServerName( self ):
return 'php-language-server'
def GetCommandLine( self ):
return [ PATH_TO_PHP, PATH_TO_SERVER ]
def SupportedFiletypes( self ):
return [ 'php' ]
def ConvertNotificationToMessage( self, request_data, notification ):
# Do the normal
message = super( PHPCompleter, self ).ConvertNotificationToMessage(
request_data,
notification )
if message is not None:
return message
# The server returns parsing status as messages, so let's show the user.
if notification[ 'method' ] == 'window/logMessage':
return responses.BuildDisplayMessageResponse(
notification[ 'params' ][ 'message' ] )