PT 147263283 - Workaround for issue in STS manifest editor

STS manifest editor deletes all error and warning markers on document
save. This is a problem with the YEdit editor that STS manifest editor
extends, and not with vscode manifest language server. This is just a
temporary workaround until STS no longer needs the YEdit-based editor
and uses LSP4E editor instead.
This commit is contained in:
nsingh
2017-06-23 15:23:05 -07:00
parent 904ac28c73
commit 5ccb92f84e
3 changed files with 72 additions and 10 deletions

View File

@@ -79,6 +79,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
private ReferencesHandler referencesHandler;
private DocumentSymbolHandler documentSymbolHandler;
private Consumer<TextDocumentSaveChange> documentSaveListener;
public SimpleTextDocumentService(SimpleLanguageServer server) {
this.server = server;
@@ -193,6 +194,10 @@ public class SimpleTextDocumentService implements TextDocumentService {
documentChangeListeners.add(l);
}
public void onDidSave(Consumer<TextDocumentSaveChange> l) {
documentSaveListener=l;
}
public synchronized TextDocument getDocument(String url) {
TrackedDocument doc = documents.get(url);
if (doc==null) {
@@ -329,6 +334,21 @@ public class SimpleTextDocumentService implements TextDocumentService {
@Override
public void didSave(DidSaveTextDocumentParams params) {
// Workaround for PT 147263283, where error markers in STS are lost on document save.
// STS 3.9.0 does not use the LSP4E editor for edit manifest.yml, which correctly retains error markers after save.
// Instead, because the LSP4E editor is missing support for hovers and completions, STS 3.9.0 uses its own manifest editor
// which extends the YEdit editor. This YEdit editor has a problem, where on save, all error markers are deleted.
// When STS uses the LSP4E editor and no longer needs its own YEdit-based editor, the issue with error markers disappearing
// on save should not be a problem anymore, and the workaround below will no longer be needed.
if (documentSaveListener != null) {
TextDocumentIdentifier docId = params.getTextDocument();
String url = docId.getUri();
Log.debug("didSave: "+url);
if (url!=null) {
TextDocument doc = getDocument(url);
documentSaveListener.accept(new TextDocumentSaveChange(doc));
}
}
}
public void publishDiagnostics(TextDocumentIdentifier docId, Collection<Diagnostic> diagnostics) {

View File

@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.languageserver.util;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
public class TextDocumentSaveChange {
private final TextDocument document;
public TextDocumentSaveChange(TextDocument doc) {
this.document = doc;
}
public TextDocument getDocument() {
return document;
}
}

View File

@@ -33,6 +33,7 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcil
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
import org.springframework.ide.vscode.commons.languageserver.util.TextDocumentContentChange;
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;
@@ -86,16 +87,17 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
IReconcileEngine engine = new YamlSchemaBasedReconcileEngine(parser, schema, quickfixes);
documents.onDidChangeContent(params -> {
TextDocument doc = params.getDocument();
if (LanguageId.CF_MANIFEST.equals(doc.getLanguageId())
|| FALLBACK_YML_ID.equals(doc.getLanguageId())) {
//
// this FALLBACK_YML_ID got introduced to workaround a limitation in LSP4E, which sets the file extension as language ID to the document
//
validateWith(doc.getId(), engine);
} else {
validateWith(doc.getId(), IReconcileEngine.NULL);
}
validateOnDocumentChange(engine, params.getDocument());
});
// Workaround for PT 147263283, where error markers in STS are lost on document save.
// STS 3.9.0 does not use the LSP4E editor for edit manifest.yml, which correctly retains error markers after save.
// Instead, because the LSP4E editor is missing support for hovers and completions, STS 3.9.0 uses its own manifest editor
// which extends the YEdit editor. This YEdit editor has a problem, where on save, all error markers are deleted.
// When STS uses the LSP4E editor and no longer needs its own YEdit-based editor, the issue with error markers disappearing
// on save should not be a problem anymore, and the workaround below will no longer be needed.
documents.onDidSave(params -> {
validateOnDocumentChange(engine, params.getDocument());
});
// workspace.onDidChangeConfiguraton(settings -> {
@@ -121,6 +123,18 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
});
}
private void validateOnDocumentChange(IReconcileEngine engine, TextDocument doc) {
if (LanguageId.CF_MANIFEST.equals(doc.getLanguageId())
|| FALLBACK_YML_ID.equals(doc.getLanguageId())) {
//
// this FALLBACK_YML_ID got introduced to workaround a limitation in LSP4E, which sets the file extension as language ID to the document
//
validateWith(doc.getId(), engine);
} else {
validateWith(doc.getId(), IReconcileEngine.NULL);
}
}
protected ManifestYmlHintProviders getHintProviders() {
Callable<Collection<YValueHint>> buildPacksProvider = new ManifestYamlCFBuildpacksProvider(getCfTargetCache());
Callable<Collection<YValueHint>> servicesProvider = new ManifestYamlCFServicesProvider(getCfTargetCache());