Avoid stray reconciler errors on language switch

This commit is contained in:
Kris De Volder
2017-05-08 14:23:58 -07:00
parent cfbe735ad4
commit a687a27d8d
4 changed files with 14 additions and 11 deletions

View File

@@ -145,6 +145,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
public void didOpen(DidOpenTextDocumentParams params) {
TextDocumentItem docId = params.getTextDocument();
String url = docId.getUri();
//Log.info("didOpen: "+params.getTextDocument().getUri());
LanguageId languageId = LanguageId.of(docId.getLanguageId());
int version = docId.getVersion();
if (url!=null) {
@@ -173,8 +174,12 @@ public class SimpleTextDocumentService implements TextDocumentService {
@Override
public void didClose(DidCloseTextDocumentParams params) {
//LOG.info("didClose: "+params.getTextDocument().getUri());
//Log.info("didClose: "+params.getTextDocument().getUri());
String url = params.getTextDocument().getUri();
//Clear diagnostics when a file is closed. This makes the errors disapear when the language is changed for
// a document (this resulst in a dicClose even as being sent to the language server if that changes make the
// document go 'out of scope'.
publishDiagnostics(params.getTextDocument(), ImmutableList.of());
if (url!=null) {
documents.remove(url);
}

View File

@@ -21,6 +21,7 @@ public class LanguageId {
public static final LanguageId PLAINTEXT = of("plaintext");
public static final LanguageId CONCOURSE_TASK = of("concourse-task-yaml");
public static final LanguageId CONCOURSE_PIPELINE = of("concourse-pipeline-yaml");
public static final LanguageId CF_MANIFEST = of("manifest-yaml");
public static final LanguageId JAVA = of("java");
public static final LanguageId YAML = of("yaml");

View File

@@ -27,6 +27,7 @@ import org.springframework.ide.vscode.commons.languageserver.hover.VscodeHoverEn
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
import org.springframework.ide.vscode.commons.yaml.ast.YamlASTProvider;
import org.springframework.ide.vscode.commons.yaml.ast.YamlParser;
@@ -75,7 +76,11 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
// SimpleWorkspaceService workspace = getWorkspaceService();
documents.onDidChangeContent(params -> {
TextDocument doc = params.getDocument();
validateWith(doc.getId(), engine);
if (LanguageId.CF_MANIFEST.equals(doc.getLanguageId())) {
validateWith(doc.getId(), engine);
} else {
validateWith(doc.getId(), IReconcileEngine.NULL);
}
});
// workspace.onDidChangeConfiguraton(settings -> {

View File

@@ -29,19 +29,11 @@ function error(msg : string) {
export function activate(context: VSCode.ExtensionContext) {
let options : commons.ActivatorOptions = {
DEBUG : false,
CONNECT_TO_LS: false,
CONNECT_TO_LS: true,
extensionId: 'vscode-manifest-yaml',
fatJarFile: 'jars/language-server.jar',
jvmHeap: '64m',
clientOptions: {
// HACK!!! documentSelector only takes string|string[] where string is language id, but DocumentFilter object is passed instead
// Reasons:
// 1. documentSelector is just passed over to functions like #registerHoverProvider(documentSelector, ...) that take documentSelector
// parameter in string | DocumentFilter | string[] | DocumentFilter[] format
// 2. Combination of non string|string[] documentSelector parameter and synchronize.textDocumentFilter function makes doc synchronization
// events pass on to Language Server only for documents for which function passed via textDocumentFilter property return true
// TODO: Remove <any> cast ones https://github.com/Microsoft/vscode-languageserver-node/issues/9 is resolved
documentSelector: ["manifest-yaml"]
}
};