2013-06-04 12:14:12 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011, 2012 Chiel ten Brinke <ctenbrinke@gmail.com>
|
2014-01-13 11:08:43 -08:00
|
|
|
# Google Inc.
|
2013-06-04 12:14:12 +02:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe 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.
|
|
|
|
#
|
|
|
|
# YouCompleteMe 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 YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-02-14 11:15:07 -07:00
|
|
|
from collections import defaultdict
|
2013-06-21 22:26:11 +02:00
|
|
|
import os
|
|
|
|
import glob
|
2013-09-30 13:40:25 -07:00
|
|
|
from ycm.completers.completer import Completer
|
2013-09-20 17:24:34 -07:00
|
|
|
from ycm.server import responses
|
|
|
|
from ycm import utils
|
2013-06-04 12:14:12 +02:00
|
|
|
import urllib2
|
|
|
|
import urllib
|
|
|
|
import urlparse
|
|
|
|
import json
|
2013-09-05 23:43:14 -07:00
|
|
|
import logging
|
2013-06-04 12:14:12 +02:00
|
|
|
|
2013-07-17 19:29:43 -07:00
|
|
|
SERVER_NOT_FOUND_MSG = ( 'OmniSharp server binary not found at {0}. ' +
|
|
|
|
'Did you compile it? You can do so by running ' +
|
2013-08-15 21:29:27 -07:00
|
|
|
'"./install.sh --omnisharp-completer".' )
|
2014-02-14 11:15:07 -07:00
|
|
|
MIN_LINES_IN_FILE_TO_PARSE = 5
|
|
|
|
INVALID_FILE_MESSAGE = 'File is invalid.'
|
|
|
|
FILE_TOO_SHORT_MESSAGE = (
|
|
|
|
'File is less than {0} lines long; not parsing.'.format(
|
|
|
|
MIN_LINES_IN_FILE_TO_PARSE ) )
|
|
|
|
NO_DIAGNOSTIC_MESSAGE = 'No diagnostic for current line!'
|
2013-07-17 19:29:43 -07:00
|
|
|
|
2013-10-08 20:52:04 -07:00
|
|
|
|
2014-02-14 11:15:07 -07:00
|
|
|
#TODO: Handle this better than dummy classes
|
|
|
|
class CsharpDiagnostic:
|
|
|
|
def __init__ ( self, ranges, location, location_extent, text, kind ):
|
|
|
|
self.ranges_ = ranges
|
|
|
|
self.location_ = location
|
|
|
|
self.location_extent_ = location_extent
|
|
|
|
self.text_ = text
|
|
|
|
self.kind_ = kind
|
|
|
|
|
|
|
|
|
|
|
|
class CsharpDiagnosticRange:
|
|
|
|
def __init__ ( self, start, end ):
|
|
|
|
self.start_ = start
|
|
|
|
self.end_ = end
|
|
|
|
|
|
|
|
|
|
|
|
class CsharpDiagnosticLocation:
|
|
|
|
def __init__ ( self, line, column, filename ):
|
|
|
|
self.line_number_ = line
|
|
|
|
self.column_number_ = column
|
|
|
|
self.filename_ = filename
|
|
|
|
|
2014-05-09 12:06:56 -07:00
|
|
|
|
2013-09-30 13:40:25 -07:00
|
|
|
class CsharpCompleter( Completer ):
|
2013-06-04 12:14:12 +02:00
|
|
|
"""
|
|
|
|
A Completer that uses the Omnisharp server as completion engine.
|
|
|
|
"""
|
|
|
|
|
2014-02-19 11:17:52 -07:00
|
|
|
subcommands = {
|
2014-05-09 12:08:29 -07:00
|
|
|
'StartServer': ( lambda self, request_data: self._StartServer(
|
2014-05-09 12:03:53 -07:00
|
|
|
request_data ) ),
|
2014-05-09 12:08:29 -07:00
|
|
|
'StopServer': ( lambda self, request_data: self._StopServer() ),
|
|
|
|
'RestartServer': ( lambda self, request_data: self._RestartServer(
|
2014-05-09 12:03:53 -07:00
|
|
|
request_data ) ),
|
2014-05-09 12:08:29 -07:00
|
|
|
'ReloadSolution': ( lambda self, request_data: self._ReloadSolution() ),
|
|
|
|
'ServerRunning': ( lambda self, request_data: self._ServerIsRunning() ),
|
|
|
|
'ServerReady': ( lambda self, request_data: self._ServerIsReady() ),
|
|
|
|
'GoToDefinition': ( lambda self, request_data: self._GoToDefinition(
|
2014-05-09 12:03:53 -07:00
|
|
|
request_data ) ),
|
2014-05-09 12:08:29 -07:00
|
|
|
'GoToDeclaration': ( lambda self, request_data: self._GoToDefinition(
|
2014-05-09 12:03:53 -07:00
|
|
|
request_data ) ),
|
2014-05-09 12:08:29 -07:00
|
|
|
'GoTo': ( lambda self, request_data: self._GoToDefinition( request_data ) )
|
2014-02-19 11:17:52 -07:00
|
|
|
}
|
|
|
|
|
2013-09-02 14:45:53 -07:00
|
|
|
def __init__( self, user_options ):
|
|
|
|
super( CsharpCompleter, self ).__init__( user_options )
|
2013-08-15 11:50:54 +02:00
|
|
|
self._omnisharp_port = None
|
2013-09-20 17:24:34 -07:00
|
|
|
self._logger = logging.getLogger( __name__ )
|
2014-02-14 11:15:07 -07:00
|
|
|
self._diagnostic_store = None
|
|
|
|
self._max_diagnostics_to_display = user_options[
|
|
|
|
'max_diagnostics_to_display' ]
|
2013-07-19 11:55:25 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-09-23 14:33:14 -07:00
|
|
|
def Shutdown( self ):
|
2013-11-21 17:10:37 +01:00
|
|
|
if ( self.user_options[ 'auto_stop_csharp_server' ] and
|
2013-08-14 18:57:41 -07:00
|
|
|
self._ServerIsRunning() ):
|
2013-07-08 14:39:43 +02:00
|
|
|
self._StopServer()
|
2013-06-04 12:14:12 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-06-04 12:14:12 +02:00
|
|
|
def SupportedFiletypes( self ):
|
|
|
|
""" Just csharp """
|
2013-06-28 21:15:05 +02:00
|
|
|
return [ 'cs' ]
|
2013-06-04 12:14:12 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-09-30 13:40:25 -07:00
|
|
|
def ComputeCandidatesInner( self, request_data ):
|
2013-09-20 17:24:34 -07:00
|
|
|
return [ responses.BuildCompletionData(
|
2013-09-05 23:43:14 -07:00
|
|
|
completion[ 'CompletionText' ],
|
|
|
|
completion[ 'DisplayText' ],
|
|
|
|
completion[ 'Description' ] )
|
|
|
|
for completion in self._GetCompletions( request_data ) ]
|
2013-06-04 12:14:12 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-06-13 23:34:34 +02:00
|
|
|
def DefinedSubcommands( self ):
|
2014-02-19 11:17:52 -07:00
|
|
|
return CsharpCompleter.subcommands.keys()
|
2013-06-13 23:34:34 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-10-08 20:52:04 -07:00
|
|
|
def OnFileReadyToParse( self, request_data ):
|
|
|
|
if ( not self._omnisharp_port and
|
|
|
|
self.user_options[ 'auto_start_csharp_server' ] ):
|
|
|
|
self._StartServer( request_data )
|
2014-02-14 11:15:07 -07:00
|
|
|
return
|
|
|
|
|
|
|
|
filename = request_data[ 'filepath' ]
|
|
|
|
contents = request_data[ 'file_data' ][ filename ][ 'contents' ]
|
|
|
|
if contents.count( '\n' ) < MIN_LINES_IN_FILE_TO_PARSE:
|
|
|
|
raise ValueError( FILE_TOO_SHORT_MESSAGE )
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
raise ValueError( INVALID_FILE_MESSAGE )
|
|
|
|
|
|
|
|
syntax_errors = self._GetResponse( '/syntaxerrors',
|
|
|
|
self._DefaultParameters( request_data ) )
|
|
|
|
|
|
|
|
diagnostics = [ self._SyntaxErrorToDiagnostic( x ) for x in
|
|
|
|
syntax_errors[ "Errors" ] ]
|
|
|
|
|
|
|
|
self._diagnostic_store = DiagnosticsToDiagStructure( diagnostics )
|
|
|
|
|
|
|
|
return [ responses.BuildDiagnosticData( x ) for x in
|
|
|
|
diagnostics[ : self._max_diagnostics_to_display ] ]
|
|
|
|
|
|
|
|
|
|
|
|
def _SyntaxErrorToDiagnostic( self, syntax_error ):
|
|
|
|
filename = syntax_error[ "FileName" ]
|
|
|
|
|
2014-05-09 12:03:53 -07:00
|
|
|
location = CsharpDiagnosticLocation( syntax_error[ "Line" ],
|
|
|
|
syntax_error[ "Column" ], filename )
|
2014-02-14 11:15:07 -07:00
|
|
|
location_range = CsharpDiagnosticRange( location, location )
|
2014-05-09 12:03:53 -07:00
|
|
|
return CsharpDiagnostic( list(),
|
|
|
|
location,
|
|
|
|
location_range,
|
|
|
|
syntax_error[ "Message" ],
|
|
|
|
"E" )
|
2014-02-14 11:15:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
def GetDetailedDiagnostic( self, request_data ):
|
|
|
|
current_line = request_data[ 'line_num' ] + 1
|
|
|
|
current_column = request_data[ 'column_num' ] + 1
|
|
|
|
current_file = request_data[ 'filepath' ]
|
|
|
|
|
|
|
|
if not self._diagnostic_store:
|
|
|
|
raise ValueError( NO_DIAGNOSTIC_MESSAGE )
|
|
|
|
|
|
|
|
diagnostics = self._diagnostic_store[ current_file ][ current_line ]
|
|
|
|
if not diagnostics:
|
|
|
|
raise ValueError( NO_DIAGNOSTIC_MESSAGE )
|
|
|
|
|
|
|
|
closest_diagnostic = None
|
|
|
|
distance_to_closest_diagnostic = 999
|
|
|
|
|
|
|
|
for diagnostic in diagnostics:
|
|
|
|
distance = abs( current_column - diagnostic.location_.column_number_ )
|
|
|
|
if distance < distance_to_closest_diagnostic:
|
|
|
|
distance_to_closest_diagnostic = distance
|
|
|
|
closest_diagnostic = diagnostic
|
|
|
|
|
|
|
|
return responses.BuildDisplayMessageResponse(
|
|
|
|
closest_diagnostic.text_ )
|
2013-10-08 20:52:04 -07:00
|
|
|
|
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def OnUserCommand( self, arguments, request_data ):
|
2013-06-13 23:34:34 +02:00
|
|
|
if not arguments:
|
2013-09-05 23:43:14 -07:00
|
|
|
raise ValueError( self.UserCommandsHelpMessage() )
|
2013-06-13 23:34:34 +02:00
|
|
|
|
|
|
|
command = arguments[ 0 ]
|
2014-02-19 11:17:52 -07:00
|
|
|
if command in CsharpCompleter.subcommands:
|
|
|
|
command_lamba = CsharpCompleter.subcommands[ command ]
|
|
|
|
return command_lamba( self, request_data )
|
|
|
|
else:
|
|
|
|
raise ValueError( self.UserCommandsHelpMessage() )
|
2013-06-13 23:34:34 +02:00
|
|
|
|
2013-07-17 18:29:34 -07:00
|
|
|
|
2013-08-14 16:34:44 +02:00
|
|
|
def DebugInfo( self ):
|
|
|
|
if self._ServerIsRunning():
|
2013-10-04 15:44:16 -07:00
|
|
|
return 'Server running at: {0}\nLogfiles:\n{1}\n{2}'.format(
|
2013-10-08 20:52:04 -07:00
|
|
|
self._ServerLocation(), self._filename_stdout, self._filename_stderr )
|
2013-08-14 16:34:44 +02:00
|
|
|
else:
|
2013-08-14 17:02:10 +02:00
|
|
|
return 'Server is not running'
|
2013-08-14 16:34:44 +02:00
|
|
|
|
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def _StartServer( self, request_data ):
|
2013-06-13 23:34:34 +02:00
|
|
|
""" Start the OmniSharp server """
|
2013-10-08 20:52:04 -07:00
|
|
|
self._logger.info( 'startup' )
|
|
|
|
|
2013-10-14 20:38:45 -07:00
|
|
|
self._omnisharp_port = utils.GetUnusedLocalhostPort()
|
2013-12-03 17:34:10 +01:00
|
|
|
solution_files, folder = _FindSolutionFiles( request_data[ 'filepath' ] )
|
2013-07-17 19:29:43 -07:00
|
|
|
|
2013-12-03 17:34:10 +01:00
|
|
|
if len( solution_files ) == 0:
|
2013-09-05 23:43:14 -07:00
|
|
|
raise RuntimeError(
|
|
|
|
'Error starting OmniSharp server: no solutionfile found' )
|
2013-12-03 17:34:10 +01:00
|
|
|
elif len( solution_files ) == 1:
|
|
|
|
solutionfile = solution_files[ 0 ]
|
2013-07-17 19:29:43 -07:00
|
|
|
else:
|
2013-11-21 15:31:38 +01:00
|
|
|
# multiple solutions found : if there is one whose name is the same
|
|
|
|
# as the folder containing the file we edit, use this one
|
|
|
|
# (e.g. if we have bla/Project.sln and we are editing
|
|
|
|
# bla/Project/Folder/File.cs, use bla/Project.sln)
|
2013-12-03 17:34:10 +01:00
|
|
|
filepath_components = _PathComponents( request_data[ 'filepath' ] )
|
|
|
|
solutionpath = _PathComponents( folder )
|
2013-11-21 15:31:38 +01:00
|
|
|
foldername = ''
|
2013-12-03 17:34:10 +01:00
|
|
|
if len( filepath_components ) > len( solutionpath ):
|
|
|
|
foldername = filepath_components[ len( solutionpath ) ]
|
2014-03-04 10:24:21 -08:00
|
|
|
solution_file_candidates = [ sfile for sfile in solution_files
|
|
|
|
if _GetFilenameWithoutExtension( sfile ) == foldername ]
|
2013-12-03 17:34:10 +01:00
|
|
|
if len( solution_file_candidates ) == 1:
|
|
|
|
solutionfile = solution_file_candidates[ 0 ]
|
2013-11-21 15:31:38 +01:00
|
|
|
else:
|
|
|
|
raise RuntimeError(
|
|
|
|
'Found multiple solution files instead of one!\n{0}'.format(
|
2013-12-03 17:34:10 +01:00
|
|
|
solution_files ) )
|
2013-07-12 14:46:33 -06:00
|
|
|
|
2013-07-17 19:29:43 -07:00
|
|
|
omnisharp = os.path.join(
|
|
|
|
os.path.abspath( os.path.dirname( __file__ ) ),
|
|
|
|
'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )
|
2013-07-12 14:46:33 -06:00
|
|
|
|
2013-07-17 19:29:43 -07:00
|
|
|
if not os.path.isfile( omnisharp ):
|
2013-09-05 23:43:14 -07:00
|
|
|
raise RuntimeError( SERVER_NOT_FOUND_MSG.format( omnisharp ) )
|
2013-07-17 19:29:43 -07:00
|
|
|
|
2013-08-14 15:40:43 +02:00
|
|
|
path_to_solutionfile = os.path.join( folder, solutionfile )
|
2013-12-10 12:46:05 +01:00
|
|
|
# we need to pass the command to Popen as a string since we're passing
|
|
|
|
# shell=True (as recommended by Python's doc)
|
2013-12-11 10:27:29 +01:00
|
|
|
command = ( omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
|
|
|
|
path_to_solutionfile )
|
2013-07-17 19:29:43 -07:00
|
|
|
|
2014-02-26 12:54:14 -07:00
|
|
|
if not utils.OnWindows() and not utils.OnCygwin():
|
2013-12-10 12:46:05 +01:00
|
|
|
command = 'mono ' + command
|
2013-07-17 19:29:43 -07:00
|
|
|
|
2014-02-26 12:54:14 -07:00
|
|
|
if utils.OnCygwin():
|
|
|
|
command = command + ' --client-path-mode Cygwin'
|
|
|
|
|
2013-09-20 17:24:34 -07:00
|
|
|
filename_format = os.path.join( utils.PathToTempDir(),
|
|
|
|
'omnisharp_{port}_{sln}_{std}.log' )
|
2013-08-14 18:57:41 -07:00
|
|
|
|
2013-08-14 16:34:44 +02:00
|
|
|
self._filename_stdout = filename_format.format(
|
2013-08-14 17:02:10 +02:00
|
|
|
port=self._omnisharp_port, sln=solutionfile, std='stdout' )
|
2013-08-14 16:34:44 +02:00
|
|
|
self._filename_stderr = filename_format.format(
|
2013-08-14 17:02:10 +02:00
|
|
|
port=self._omnisharp_port, sln=solutionfile, std='stderr' )
|
2013-06-13 23:34:34 +02:00
|
|
|
|
2013-08-14 16:34:44 +02:00
|
|
|
with open( self._filename_stderr, 'w' ) as fstderr:
|
|
|
|
with open( self._filename_stdout, 'w' ) as fstdout:
|
2013-12-10 12:46:05 +01:00
|
|
|
# shell=True is needed for Windows so OmniSharp does not spawn
|
|
|
|
# in a new visible window
|
2013-12-11 13:41:04 +01:00
|
|
|
utils.SafePopen( command, stdout=fstdout, stderr=fstderr, shell=True )
|
2013-07-19 11:31:52 +02:00
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
self._logger.info( 'Starting OmniSharp server' )
|
2013-06-13 23:34:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _StopServer( self ):
|
|
|
|
""" Stop the OmniSharp server """
|
2013-07-08 11:39:17 +02:00
|
|
|
self._GetResponse( '/stopserver' )
|
2013-08-15 11:50:54 +02:00
|
|
|
self._omnisharp_port = None
|
2013-09-05 23:43:14 -07:00
|
|
|
self._logger.info( 'Stopping OmniSharp server' )
|
2013-06-13 23:34:34 +02:00
|
|
|
|
|
|
|
|
2014-02-19 11:17:52 -07:00
|
|
|
def _RestartServer ( self, request_data ):
|
|
|
|
""" Restarts the OmniSharp server """
|
|
|
|
if self._ServerIsRunning():
|
|
|
|
self._StopServer()
|
|
|
|
return self._StartServer( request_data )
|
|
|
|
|
|
|
|
|
2014-01-28 10:31:45 -07:00
|
|
|
def _ReloadSolution( self ):
|
|
|
|
""" Reloads the solutions in the OmniSharp server """
|
|
|
|
self._logger.info( 'Reloading Solution in OmniSharp server' )
|
|
|
|
return self._GetResponse( '/reloadsolution' )
|
|
|
|
|
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def _GetCompletions( self, request_data ):
|
2013-08-15 12:17:42 +02:00
|
|
|
""" Ask server for completions """
|
2013-09-05 23:43:14 -07:00
|
|
|
completions = self._GetResponse( '/autocomplete',
|
|
|
|
self._DefaultParameters( request_data ) )
|
2013-08-15 12:17:42 +02:00
|
|
|
return completions if completions != None else []
|
|
|
|
|
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def _GoToDefinition( self, request_data ):
|
2013-08-16 21:00:26 +02:00
|
|
|
""" Jump to definition of identifier under cursor """
|
2013-09-05 23:43:14 -07:00
|
|
|
definition = self._GetResponse( '/gotodefinition',
|
|
|
|
self._DefaultParameters( request_data ) )
|
2013-08-16 21:00:26 +02:00
|
|
|
if definition[ 'FileName' ] != None:
|
2013-09-20 17:24:34 -07:00
|
|
|
return responses.BuildGoToResponse( definition[ 'FileName' ],
|
2014-03-14 10:57:24 -06:00
|
|
|
definition[ 'Line' ] - 1,
|
|
|
|
definition[ 'Column' ] - 1 )
|
2013-08-16 21:00:26 +02:00
|
|
|
else:
|
2013-09-05 23:43:14 -07:00
|
|
|
raise RuntimeError( 'Can\'t jump to definition' )
|
2013-08-16 21:00:26 +02:00
|
|
|
|
2013-08-15 12:17:42 +02:00
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def _DefaultParameters( self, request_data ):
|
2013-08-16 21:00:26 +02:00
|
|
|
""" Some very common request parameters """
|
2013-08-15 12:17:42 +02:00
|
|
|
parameters = {}
|
2013-09-05 23:43:14 -07:00
|
|
|
parameters[ 'line' ] = request_data[ 'line_num' ] + 1
|
|
|
|
parameters[ 'column' ] = request_data[ 'column_num' ] + 1
|
|
|
|
filepath = request_data[ 'filepath' ]
|
|
|
|
parameters[ 'buffer' ] = request_data[ 'file_data' ][ filepath ][
|
|
|
|
'contents' ]
|
|
|
|
parameters[ 'filename' ] = filepath
|
2013-08-16 21:00:26 +02:00
|
|
|
return parameters
|
2013-08-15 12:17:42 +02:00
|
|
|
|
|
|
|
|
2013-08-15 11:50:54 +02:00
|
|
|
def _ServerIsRunning( self ):
|
|
|
|
""" Check if our OmniSharp server is running """
|
2013-10-09 13:17:53 -07:00
|
|
|
try:
|
|
|
|
return bool( self._omnisharp_port and
|
|
|
|
self._GetResponse( '/checkalivestatus', silent = True ) )
|
|
|
|
except:
|
|
|
|
return False
|
2013-07-15 09:12:32 -06:00
|
|
|
|
2013-07-19 11:55:25 +02:00
|
|
|
|
2014-02-19 09:48:22 -07:00
|
|
|
def _ServerIsReady( self ):
|
|
|
|
""" Check if our OmniSharp server is ready """
|
|
|
|
try:
|
|
|
|
return bool( self._omnisharp_port and
|
2014-05-09 12:19:22 -07:00
|
|
|
self._GetResponse( '/checkreadystatus', silent = True ) )
|
2014-02-19 09:48:22 -07:00
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2013-10-08 20:52:04 -07:00
|
|
|
def _ServerLocation( self ):
|
|
|
|
return 'http://localhost:' + str( self._omnisharp_port )
|
2013-07-19 11:55:25 +02:00
|
|
|
|
2013-07-16 12:33:07 +02:00
|
|
|
|
2013-10-08 20:52:04 -07:00
|
|
|
def _GetResponse( self, handler, parameters = {}, silent = False ):
|
2013-06-13 23:34:34 +02:00
|
|
|
""" Handle communication with server """
|
2013-09-05 23:43:14 -07:00
|
|
|
# TODO: Replace usage of urllib with Requests
|
2013-10-08 20:52:04 -07:00
|
|
|
target = urlparse.urljoin( self._ServerLocation(), handler )
|
2013-06-04 12:14:12 +02:00
|
|
|
parameters = urllib.urlencode( parameters )
|
2013-09-05 23:43:14 -07:00
|
|
|
response = urllib2.urlopen( target, parameters )
|
|
|
|
return json.loads( response.read() )
|
2013-07-17 18:29:34 -07:00
|
|
|
|
|
|
|
|
2013-09-05 23:43:14 -07:00
|
|
|
def _FindSolutionFiles( filepath ):
|
2013-08-16 21:00:26 +02:00
|
|
|
""" Find solution files by searching upwards in the file tree """
|
2013-09-05 23:43:14 -07:00
|
|
|
folder = os.path.dirname( filepath )
|
2013-07-17 18:29:34 -07:00
|
|
|
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
|
|
while not solutionfiles:
|
|
|
|
lastfolder = folder
|
|
|
|
folder = os.path.dirname( folder )
|
|
|
|
if folder == lastfolder:
|
|
|
|
break
|
|
|
|
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
|
|
return solutionfiles, folder
|
2013-11-21 15:31:38 +01:00
|
|
|
|
2014-05-09 12:03:53 -07:00
|
|
|
|
2013-12-03 17:34:10 +01:00
|
|
|
def _PathComponents( path ):
|
|
|
|
path_components = []
|
2013-11-21 15:31:38 +01:00
|
|
|
while True:
|
|
|
|
path, folder = os.path.split( path )
|
|
|
|
if folder:
|
2013-12-03 17:34:10 +01:00
|
|
|
path_components.append( folder )
|
2013-11-21 15:31:38 +01:00
|
|
|
else:
|
|
|
|
if path:
|
2013-12-03 17:34:10 +01:00
|
|
|
path_components.append( path )
|
2013-11-21 15:31:38 +01:00
|
|
|
break
|
2013-12-03 17:34:10 +01:00
|
|
|
path_components.reverse()
|
|
|
|
return path_components
|
2013-11-21 15:31:38 +01:00
|
|
|
|
2014-05-09 12:03:53 -07:00
|
|
|
|
2013-11-21 15:31:38 +01:00
|
|
|
def _GetFilenameWithoutExtension( path ):
|
|
|
|
return os.path.splitext( os.path.basename ( path ) )[ 0 ]
|
|
|
|
|
2014-05-09 12:03:53 -07:00
|
|
|
|
2014-02-14 11:15:07 -07:00
|
|
|
def DiagnosticsToDiagStructure( diagnostics ):
|
|
|
|
structure = defaultdict( lambda : defaultdict( list ) )
|
|
|
|
for diagnostic in diagnostics:
|
|
|
|
structure[ diagnostic.location_.filename_ ][
|
|
|
|
diagnostic.location_.line_number_ ].append( diagnostic )
|
|
|
|
return structure
|