From 7d7349142cf9491f62a89e8c8e84159694ba0283 Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Tue, 4 Jun 2013 12:14:12 +0200 Subject: [PATCH] completer rewritten to fit in the changed api --- python/ycm/completers/cs/__init__.py | 0 python/ycm/completers/cs/cs_completer.py | 74 ++++++++++++++++++++++++ python/ycm/completers/cs/hook.py | 21 +++++++ 3 files changed, 95 insertions(+) create mode 100644 python/ycm/completers/cs/__init__.py create mode 100755 python/ycm/completers/cs/cs_completer.py create mode 100644 python/ycm/completers/cs/hook.py diff --git a/python/ycm/completers/cs/__init__.py b/python/ycm/completers/cs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py new file mode 100755 index 00000000..c5205106 --- /dev/null +++ b/python/ycm/completers/cs/cs_completer.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# +# Copyright (C) 2011, 2012 Chiel ten Brinke +# Strahinja Val Markovic +# +# 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 . + +import vim +from ycm.completers.threaded_completer import ThreadedCompleter +from ycm import vimsupport + +# Import stuff for Omnisharp +import urllib2 +import urllib +import urlparse +import json + + +class CsharpCompleter( ThreadedCompleter ): + """ + A Completer that uses the Omnisharp server as completion engine. + """ + + def __init__( self ): + super( CsharpCompleter, self ).__init__() + + def SupportedFiletypes( self ): + """ Just csharp """ + return ['cs'] + + def ComputeCandidates( self, unused_query, unused_start_column ): + return [ { 'word': str( completion['CompletionText'] ), + 'menu': str( completion['Description'] ), + 'info': str( completion['DisplayText'] ) } + for completion in self.getCompletions() ] + + def getCompletions( self ): + """Ask server for completions""" + line, column = vimsupport.CurrentLineAndColumn() + + parameters = {} + parameters['line'], parameters['column'] = line + 1, column + 1 + parameters['buffer'] = '\n'.join( vim.current.buffer ) + parameters['filename'] = vim.current.buffer.name + + js = self.getResponse( '/autocomplete', parameters ) + if(js != ''): + completions = json.loads( js ) + return completions + return [] + + def getResponse( self, endPoint, parameters={} ): + """Handle communication with server""" + target = urlparse.urljoin( vim.eval( 'g:OmniSharp_host' ), endPoint ) + parameters = urllib.urlencode( parameters ) + try: + response = urllib2.urlopen( target, parameters ) + return response.read() + except: + vim.command( "echoerr 'Could not connect to " + target + "'" ) + return '' diff --git a/python/ycm/completers/cs/hook.py b/python/ycm/completers/cs/hook.py new file mode 100644 index 00000000..d082bbcc --- /dev/null +++ b/python/ycm/completers/cs/hook.py @@ -0,0 +1,21 @@ +# Copyright (C) 2011, 2012 Chiel ten Brinke +# +# 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 . + +from ycm.completers.cs.cs_completer import CsharpCompleter + +def GetCompleter(): + return CsharpCompleter()