def document_did_close(self, params): codeeditor = params['codeeditor'] logger.debug('[{0}] File: {1}'.format( LSPRequestTypes.DOCUMENT_DID_CLOSE, params['file'])) filename = path_as_uri(params['file']) params = {'textDocument': {'uri': filename}} if filename not in self.watched_files: params[ClientConstants.CANCEL] = True else: editors = self.watched_files[filename] if len(editors) > 1: params[ClientConstants.CANCEL] = True idx = -1 for i, editor in enumerate(editors): if id(codeeditor) == id(editor): idx = i break if idx > 0: editors.pop(idx) if len(editors) == 0: self.watched_files.pop(filename) return params
def document_symbol_request(self, params): params = { 'textDocument': { 'uri': path_as_uri(params['file']) }, } return params
def send_workspace_folders_change(self, params): folder = params['folder'] workspace_watcher = params['instance'] folder_uri = path_as_uri(folder) added_folders = [] removed_folders = [] if params['kind'] == 'addition': if folder not in self.watched_folders: self.watched_folders[folder] = { 'uri': folder_uri, 'instance': workspace_watcher } added_folders.append({ 'uri': folder_uri, 'name': folder }) elif params['kind'] == 'deletion': if folder not in self.watched_folders: self.watched_folders.pop(folder) removed_folders.append({ 'uri': folder_uri, 'name': folder }) workspace_settings = self.server_capabilites['workspace'] request_params = { 'added': added_folders, 'removed': removed_folders } if not workspace_settings['workspaceFolders']['supported']: request_params[ClientConstants.CANCEL] = True return request_params
def document_will_save_notification(self, params): params = { 'textDocument': { 'uri': path_as_uri(params['file']) }, 'reason': params['reason'] } return params
def send_watched_files_change(self, params): changes = [] entries = params.get('params', []) for entry in entries: changes.append({ 'uri': path_as_uri(entry['file']), 'type': entry['kind'] }) params = {'changes': changes} return params
def document_changed(self, params): params = { 'textDocument': { 'uri': path_as_uri(params['file']), 'version': params['version'] }, 'contentChanges': [{ 'text': params['text'] }] } return params
def document_did_save_notification(self, params): """ Handle the textDocument/didSave message received from an LSP server. """ text = None if 'text' in params: text = params['text'] params = {'textDocument': {'uri': path_as_uri(params['file'])}} if text is not None: params['text'] = text return params
def document_range_formatting_request(self, params): options = params['options'] options = {snake_to_camel(opt): options[opt] for opt in options} params = { 'textDocument': { 'uri': path_as_uri(params['file']) }, 'options': options, 'range': params['range'] } return params
def document_completion_request(self, params): params = { 'textDocument': { 'uri': path_as_uri(params['file']) }, 'position': { 'line': params['line'], 'character': params['column'] } } return params
def document_open(self, editor_params): uri = path_as_uri(editor_params['file']) if uri not in self.watched_files: self.register_file(editor_params['file'], editor_params['codeeditor']) params = { 'textDocument': { 'uri': uri, 'languageId': editor_params['language'], 'version': editor_params['version'], 'text': editor_params['text'] } } return params
def send_workspace_folders_change(self, params): folder = params['folder'] workspace_watcher = params['instance'] folder_uri = path_as_uri(folder) added_folders = [] removed_folders = [] if params['kind'] == WorkspaceUpdateKind.ADDITION: if folder not in self.watched_folders: self.watched_folders[folder] = { 'uri': folder_uri, 'instance': workspace_watcher } added_folders.append({ 'uri': folder_uri, 'name': folder }) elif params['kind'] == WorkspaceUpdateKind.DELETION: if folder in self.watched_folders: self.watched_folders.pop(folder) removed_folders.append({ 'uri': folder_uri, 'name': folder }) workspace_settings = self.server_capabilites['workspace'] request_params = { 'event': { 'added': added_folders, 'removed': removed_folders } } if workspace_settings['workspaceFolders']['supported']: logger.debug( u'Workspace folders change: {0} -> {1}'.format( folder, params['kind']) ) else: request_params[ClientConstants.CANCEL] = True return request_params
def document_did_close(self, params): codeeditor = params['codeeditor'] filename = path_as_uri(params['file']) params = {'textDocument': {'uri': filename}} if filename not in self.watched_files: params[ClientConstants.CANCEL] = True else: editors = self.watched_files[filename] if len(editors) > 1: params[ClientConstants.CANCEL] = True idx = -1 for i, editor in enumerate(editors): if id(codeeditor) == id(editor): idx = i break if idx > 0: editors.pop(idx) if len(editors) == 0: self.watched_files.pop(filename) return params
def register_file(self, filename, codeeditor): filename = path_as_uri(filename) if filename not in self.watched_files: self.watched_files[filename] = [] self.watched_files[filename].append(codeeditor)
def folding_range_request(self, params): params = {'textDocument': {'uri': path_as_uri(params['file'])}} return params