Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 181, 179 #182

Merged
merged 4 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions server/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"request": "attach",
"port": 6003,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/server/server.js"],
"trace": true
"outFiles": ["${workspaceFolder}/out/server/server.js"]
}
]
}
51 changes: 34 additions & 17 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -200,19 +212,24 @@ 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
diagnostics.push(diagnosticResults[diagnosticItem]);
}

connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: removeDuplicatesObj(diagnostics) });
}, function (error) { });
}, (error) => { });
}
7 changes: 1 addition & 6 deletions server/src/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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)
};
Expand All @@ -52,8 +49,6 @@ export interface ClientSettings {
export interface LanguageService {
configure(settings: LanguageSettings, clientSettings: ClientSettings): void;
doValidation(document: TextDocument, yamlDocument: YAMLDocument): Thenable<Diagnostic[]>;
doResolve(item: CompletionItem): Thenable<CompletionItem>;
doComplete(document: TextDocument, position: Position, doc: YAMLDocument): Thenable<CompletionList>;
findDocumentSymbols(document: TextDocument, doc: YAMLDocument): SymbolInformation[];
doHover(document: TextDocument, position: Position, doc: YAMLDocument): Thenable<Hover>;
}
4 changes: 3 additions & 1 deletion src/ansibleCompletionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -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*#*.*$');
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/Ansible.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<key>contentName</key>
<string>string.other.ansible</string>
<key>end</key>
<string>\"?\s</string>
<string>\"?\s?</string>
<key>name</key>
<string>variable.complex.ansible</string>
<key>patterns</key>
Expand Down