From a207d7153b5c3507933e5c65e1d76ef438b18290 Mon Sep 17 00:00:00 2001 From: yungez Date: Mon, 17 Sep 2018 17:03:43 +0800 Subject: [PATCH 1/4] fix 181, 179 --- src/ansibleCompletionItemProvider.ts | 4 +++- syntaxes/Ansible.tmLanguage | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ansibleCompletionItemProvider.ts b/src/ansibleCompletionItemProvider.ts index f5e5f42..a2b9e6b 100644 --- a/src/ansibleCompletionItemProvider.ts +++ b/src/ansibleCompletionItemProvider.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode'; import { CompletionEngine } from './completionEngine'; -import { Range } from 'vscode-languageclient/lib/main'; import * as utilities from './utilities'; const pattern_variable = new RegExp('\\S+: \".*{{\\s*(}}.)*\"*\\s*#*.*$'); @@ -23,6 +22,9 @@ export class AnsibleCompletionItemProvider implements vscode.CompletionItemProvi let lineText = document.lineAt(position.line).text; // provide auto completion for property name only, not on value + if (!range) { + return; + } var index = lineText.indexOf(':'); if (index != -1 && index < range.end.character) { return; diff --git a/syntaxes/Ansible.tmLanguage b/syntaxes/Ansible.tmLanguage index 329b89b..ee065dd 100644 --- a/syntaxes/Ansible.tmLanguage +++ b/syntaxes/Ansible.tmLanguage @@ -69,7 +69,7 @@ contentName string.other.ansible end - \"?\s + \"?\s? name variable.complex.ansible patterns From 3a7e1e4ba21910dd190862ac93c68dd03c3d80ba Mon Sep 17 00:00:00 2001 From: yungez Date: Mon, 17 Sep 2018 17:23:09 +0800 Subject: [PATCH 2/4] remove trace --- server/.vscode/launch.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/.vscode/launch.json b/server/.vscode/launch.json index 6dacf1a..fa9cc84 100644 --- a/server/.vscode/launch.json +++ b/server/.vscode/launch.json @@ -10,8 +10,7 @@ "request": "attach", "port": 6003, "sourceMaps": true, - "outFiles": ["${workspaceFolder}/out/server/server.js"], - "trace": true + "outFiles": ["${workspaceFolder}/out/server/server.js"] } ] } \ No newline at end of file From 726bf211120deca68a2eba9d091c7f1fbd49d18b Mon Sep 17 00:00:00 2001 From: yungez Date: Tue, 18 Sep 2018 16:56:41 +0800 Subject: [PATCH 3/4] refine code --- server/src/server.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 972e808..e7fd6aa 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -200,13 +200,18 @@ function validateTextDocument(textDocument: TextDocument): void { } if (textDocument.getText().length === 0) { - connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] }); return; } let yamlDocument = parseYAML(textDocument.getText(), []); - languageService.doValidation(textDocument, yamlDocument).then(function (diagnosticResults) { + if (!yamlDocument) { + return; + } + languageService.doValidation(textDocument, yamlDocument).then((diagnosticResults) => { + if (!diagnosticResults) { + return; + } let diagnostics = []; for (let diagnosticItem in diagnosticResults) { diagnosticResults[diagnosticItem].severity = 1; //Convert all warnings to errors @@ -214,5 +219,5 @@ function validateTextDocument(textDocument: TextDocument): void { } connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: removeDuplicatesObj(diagnostics) }); - }, function (error) { }); + }, (error) => { }); } \ No newline at end of file From de505e2f3279237d686cbb3d810b6fa1f2d6d645 Mon Sep 17 00:00:00 2001 From: yungez Date: Thu, 20 Sep 2018 15:47:29 +0800 Subject: [PATCH 4/4] more try/catch --- server/src/server.ts | 40 ++++++++++++++++++++----------- server/src/yamlLanguageService.ts | 7 +----- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index e7fd6aa..2d0aa37 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -36,8 +36,6 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { let workspaceFolders = params['workspaceFolders']; let workspaceRoot = params.rootPath; - let symbolSupport = hasClientCapability(params, 'workspace', 'symbol', 'dynamicRegistration'); - return { capabilities: { textDocumentSync: documents.syncKind, @@ -166,31 +164,45 @@ function updateConfiguration() { } documents.onDidChangeContent((textDocumentChangeEvent) => { - triggerValidation(textDocumentChangeEvent.document); + try { + triggerValidation(textDocumentChangeEvent.document); + } catch { + } }); documents.onDidClose(textDocumentChangeEvent => { - cleanPendingValidation(textDocumentChangeEvent.document); - connection.sendDiagnostics({ uri: textDocumentChangeEvent.document.uri, diagnostics: [] }); + try { + cleanPendingValidation(textDocumentChangeEvent.document); + connection.sendDiagnostics({ uri: textDocumentChangeEvent.document.uri, diagnostics: [] }); + } catch { + } }); let pendingValidationRequests: { [uri: string]: NodeJS.Timer; } = {}; const validationDelayMs = 200; function cleanPendingValidation(textDocument: TextDocument): void { - let request = pendingValidationRequests[textDocument.uri]; - if (request) { - clearTimeout(request); - delete pendingValidationRequests[textDocument.uri]; + try { + let request = pendingValidationRequests[textDocument.uri]; + if (request) { + clearTimeout(request); + delete pendingValidationRequests[textDocument.uri]; + } + } catch { + } } function triggerValidation(textDocument: TextDocument): void { - cleanPendingValidation(textDocument); - pendingValidationRequests[textDocument.uri] = setTimeout(() => { - delete pendingValidationRequests[textDocument.uri]; - validateTextDocument(textDocument); - }, validationDelayMs); + try { + cleanPendingValidation(textDocument); + pendingValidationRequests[textDocument.uri] = setTimeout(() => { + delete pendingValidationRequests[textDocument.uri]; + validateTextDocument(textDocument); + }, validationDelayMs); + } + catch { + } } function validateTextDocument(textDocument: TextDocument): void { diff --git a/server/src/yamlLanguageService.ts b/server/src/yamlLanguageService.ts index b9a7284..2b2f131 100644 --- a/server/src/yamlLanguageService.ts +++ b/server/src/yamlLanguageService.ts @@ -6,7 +6,7 @@ import { YAMLValidation } from 'yaml-language-server/out/server/src/languageserv import { JSONSchemaService } from 'yaml-language-server/out/server/src/languageservice/services/jsonSchemaService'; import { schemaContributions } from 'vscode-json-languageservice/lib/umd/services/configuration'; -import { TextDocument, Diagnostic, CompletionItem, SymbolInformation, Position, CompletionList, Hover, TextEdit, FormattingOptions } from 'vscode-languageserver'; +import { TextDocument, Diagnostic, SymbolInformation, Position, Hover } from 'vscode-languageserver'; import { YAMLHover } from './services/yamlHover'; export function getLanguageService(schemaRequestService: SchemaRequestService, workspaceContext, clientSettings: ClientSettings, promiseConstructor?): LanguageService { @@ -19,7 +19,6 @@ export function getLanguageService(schemaRequestService: SchemaRequestService, w let documentSymbol = new YamlDocumentSymbols(); let yamlvalidation = new YAMLValidation(jsonSchemaService, promise); let languagesettings: LanguageSettings = { - schemas: [], validate: clientSettings.validation }; yamlvalidation.configure(languagesettings); @@ -37,8 +36,6 @@ export function getLanguageService(schemaRequestService: SchemaRequestService, w yamlvalidation.configure(settings); }, doValidation: yamlvalidation.doValidation.bind(yamlvalidation), - doResolve: void 0, - doComplete: void 0, findDocumentSymbols: documentSymbol.findDocumentSymbols.bind(documentSymbol), doHover: hover.doHover.bind(hover) }; @@ -52,8 +49,6 @@ export interface ClientSettings { export interface LanguageService { configure(settings: LanguageSettings, clientSettings: ClientSettings): void; doValidation(document: TextDocument, yamlDocument: YAMLDocument): Thenable; - doResolve(item: CompletionItem): Thenable; - doComplete(document: TextDocument, position: Position, doc: YAMLDocument): Thenable; findDocumentSymbols(document: TextDocument, doc: YAMLDocument): SymbolInformation[]; doHover(document: TextDocument, position: Position, doc: YAMLDocument): Thenable; } \ No newline at end of file