Enable concourse editor for task files.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Central place to define constants for the known language-ids that we care
|
||||
* about.
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class LanguageIds {
|
||||
|
||||
public static final String PLAINTEXT = "plaintext";
|
||||
public static final String CONCOURSE_TASK = "concourse-task-yaml";
|
||||
public static final String CONCOURSE_PIPELINE = "concourse-pipeline-yaml";
|
||||
|
||||
}
|
||||
@@ -13,5 +13,10 @@ package org.springframework.ide.vscode.commons.languageserver.reconcile;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
public interface IReconcileEngine {
|
||||
IReconcileEngine NULL = (d, p) -> {
|
||||
p.beginCollecting();
|
||||
p.endCollecting();
|
||||
};
|
||||
|
||||
public void reconcile(IDocument doc, IProblemCollector problemCollector);
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.Futures;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -113,7 +113,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
String url = docId.getUri();
|
||||
//LOG.info("didChange: "+url);
|
||||
if (url!=null) {
|
||||
TextDocument doc = getOrCreateDocument(url);
|
||||
TextDocument doc = getDocument(url);
|
||||
for (TextDocumentContentChangeEvent change : params.getContentChanges()) {
|
||||
doc.apply(change);
|
||||
didChangeContent(doc, change);
|
||||
@@ -141,9 +141,10 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
// }
|
||||
//}
|
||||
String url = params.getTextDocument().getUri();
|
||||
String languageId = params.getTextDocument().getLanguageId();
|
||||
if (url!=null) {
|
||||
String text = params.getTextDocument().getText();
|
||||
TextDocument doc = getOrCreateDocument(url);
|
||||
TextDocument doc = createDocument(url, languageId);
|
||||
doc.setText(text);
|
||||
TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent() {
|
||||
@Override
|
||||
@@ -175,7 +176,6 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void didChangeContent(TextDocument doc, TextDocumentContentChangeEvent change) {
|
||||
documentChangeListeners.fire(new TextDocumentContentChange(doc, change));
|
||||
}
|
||||
@@ -184,14 +184,24 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
documentChangeListeners.add(l);
|
||||
}
|
||||
|
||||
private synchronized TextDocument getOrCreateDocument(String url) {
|
||||
private synchronized TextDocument getDocument(String url) {
|
||||
TextDocument doc = documents.get(url);
|
||||
if (doc==null) {
|
||||
documents.put(url, doc = new TextDocument(url));
|
||||
LOG.warning("Trying to get document ["+url+"] but it did not exists. Creating it with language-id 'plaintext'");
|
||||
doc = createDocument(url, LanguageIds.PLAINTEXT);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
private synchronized TextDocument createDocument(String url, String languageId) {
|
||||
if (documents.get(url)!=null) {
|
||||
LOG.warning("Creating document ["+url+"] but it already exists. Existing document discarded!");
|
||||
}
|
||||
TextDocument doc = new TextDocument(url, languageId);
|
||||
documents.put(url, doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
public final static CompletionList NO_COMPLETIONS = new CompletionList(false, Collections.emptyList());
|
||||
|
||||
public final static CompletableFuture<Hover> NO_HOVER = CompletableFuture.completedFuture(new Hover(ImmutableList.of(), null));
|
||||
@@ -220,12 +230,12 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
if (h!=null) {
|
||||
return hoverHandler.handle(position);
|
||||
}
|
||||
return Futures.of(null);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams position) {
|
||||
return Futures.of(null);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked"})
|
||||
@@ -241,47 +251,47 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CodeLens> resolveCodeLens(CodeLens unresolved) {
|
||||
return Futures.of(null);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
|
||||
return Futures.of(null);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,12 +314,6 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(TextDocumentPositionParams position) {
|
||||
return Futures.of(Collections.emptyList());
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
public void onDefinition(TextDocumentPositionParams h) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,16 +27,19 @@ public class TextDocument implements IDocument {
|
||||
|
||||
ILineTracker lineTracker = new DefaultLineTracker();
|
||||
private static final Pattern NEWLINE = Pattern.compile("\\r|\\n|\\r\\n|\\n\\r");
|
||||
|
||||
|
||||
private final String languageId;
|
||||
private final String uri;
|
||||
private Text text = new Text("");
|
||||
|
||||
public TextDocument(String uri) {
|
||||
public TextDocument(String uri, String languageId) {
|
||||
this.uri = uri;
|
||||
this.languageId = languageId;
|
||||
}
|
||||
|
||||
private TextDocument(TextDocument other) {
|
||||
this.uri = other.uri;
|
||||
this.languageId = other.getLanguageId();
|
||||
this.text = other.text;
|
||||
this.lineTracker.set(text.toString());
|
||||
}
|
||||
@@ -59,7 +62,7 @@ public class TextDocument implements IDocument {
|
||||
this.text = new Text(text);
|
||||
this.lineTracker.set(text);
|
||||
}
|
||||
|
||||
|
||||
public void apply(TextDocumentContentChangeEvent change) throws BadLocationException {
|
||||
Range rng = change.getRange();
|
||||
if (rng==null) {
|
||||
@@ -249,4 +252,8 @@ public class TextDocument implements IDocument {
|
||||
}
|
||||
}
|
||||
|
||||
public String getLanguageId() {
|
||||
return languageId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ import org.yaml.snakeyaml.nodes.Node;
|
||||
|
||||
/**
|
||||
* Yaml editor mock for the tests.
|
||||
*
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
class MockYamlEditor {
|
||||
|
||||
|
||||
private Yaml yaml;
|
||||
private YamlASTProvider parser;
|
||||
|
||||
@@ -41,7 +41,7 @@ class MockYamlEditor {
|
||||
this.yaml = new Yaml();
|
||||
this.parser = new YamlParser(yaml);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "YamlEditor("+text+")";
|
||||
@@ -49,14 +49,18 @@ class MockYamlEditor {
|
||||
|
||||
public SRootNode parseStructure() throws Exception {
|
||||
YamlStructureProvider sp = YamlStructureProvider.DEFAULT;
|
||||
TextDocument _doc = new TextDocument(null);
|
||||
TextDocument _doc = new TextDocument(null, getLanguageId());
|
||||
_doc.setText(text);
|
||||
YamlDocument doc = new YamlDocument(_doc, sp);
|
||||
return sp.getStructure(doc);
|
||||
}
|
||||
|
||||
|
||||
protected String getLanguageId() {
|
||||
return "yaml";
|
||||
}
|
||||
|
||||
public YamlFileAST parse() throws Exception {
|
||||
TextDocument _doc = new TextDocument(null);
|
||||
TextDocument _doc = new TextDocument(null, getLanguageId());
|
||||
_doc.setText(text);
|
||||
return parser.getAST(_doc);
|
||||
}
|
||||
@@ -91,7 +95,7 @@ class MockYamlEditor {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public String textBetween(int start, int end) {
|
||||
return text.substring(start, end);
|
||||
}
|
||||
@@ -107,5 +111,5 @@ class MockYamlEditor {
|
||||
int end = node.getEndMark().getIndex();
|
||||
return textBetween(start, end);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -93,9 +93,11 @@ public class Editor {
|
||||
|
||||
private int selectionStart;
|
||||
private Set<String> ignoredTypes;
|
||||
private String languageId;
|
||||
|
||||
public Editor(LanguageServerHarness harness, String contents) throws Exception {
|
||||
public Editor(LanguageServerHarness harness, String contents, String languageId) throws Exception {
|
||||
this.harness = harness;
|
||||
this.languageId = languageId;
|
||||
EditorState state = new EditorState(contents);
|
||||
this.document = harness.openDocument(harness.createWorkingCopy(state.documentContents));
|
||||
this.selectionStart = state.selectionStart;
|
||||
@@ -329,7 +331,7 @@ public class Editor {
|
||||
@Override
|
||||
public Editor clone() {
|
||||
try {
|
||||
return new Editor(harness, getText());
|
||||
return new Editor(harness, getText(), getLanguageId());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -556,4 +558,8 @@ public class Editor {
|
||||
return new Range(document.toPosition(start), document.toPosition(start+focusSnippet.length()));
|
||||
}
|
||||
|
||||
public String getLanguageId() {
|
||||
return languageId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
@@ -52,6 +51,7 @@ import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.services.LanguageClientAware;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient;
|
||||
|
||||
@@ -62,6 +62,7 @@ public class LanguageServerHarness {
|
||||
private Random random = new Random();
|
||||
|
||||
private Callable<? extends LanguageServer> factory;
|
||||
private String defaultLanguageId;
|
||||
|
||||
private LanguageServer server;
|
||||
|
||||
@@ -70,8 +71,14 @@ public class LanguageServerHarness {
|
||||
private Map<String,TextDocumentInfo> documents = new HashMap<>();
|
||||
private Map<String, PublishDiagnosticsParams> diagnostics = new HashMap<>();
|
||||
|
||||
public LanguageServerHarness(Callable<? extends LanguageServer> factory) throws Exception {
|
||||
|
||||
public LanguageServerHarness(Callable<? extends LanguageServer> factory, String defaultLanguageId) {
|
||||
this.factory = factory;
|
||||
this.defaultLanguageId = defaultLanguageId;
|
||||
}
|
||||
|
||||
public LanguageServerHarness(Callable<? extends LanguageServer> factory) throws Exception {
|
||||
this(factory, LanguageIds.PLAINTEXT);
|
||||
}
|
||||
|
||||
public synchronized TextDocumentInfo getOrReadFile(File file) throws Exception {
|
||||
@@ -90,7 +97,7 @@ public class LanguageServerHarness {
|
||||
document.setText(content);
|
||||
document.setUri(file.toURI().toString());
|
||||
document.setVersion(getFirstVersion());
|
||||
document.setLanguageId(getLanguageId());
|
||||
document.setLanguageId(getDefaultLanguageId());
|
||||
return new TextDocumentInfo(document);
|
||||
}
|
||||
|
||||
@@ -109,8 +116,8 @@ public class LanguageServerHarness {
|
||||
return Charset.forName("utf8");
|
||||
}
|
||||
|
||||
protected String getLanguageId() {
|
||||
return "plaintext";
|
||||
protected String getDefaultLanguageId() {
|
||||
return defaultLanguageId;
|
||||
}
|
||||
|
||||
protected String getFileExtension() {
|
||||
@@ -320,12 +327,12 @@ public class LanguageServerHarness {
|
||||
}
|
||||
|
||||
public Editor newEditor(String contents) throws Exception {
|
||||
return new Editor(this, contents);
|
||||
return new Editor(this, contents, getDefaultLanguageId());
|
||||
}
|
||||
|
||||
public synchronized TextDocumentInfo createWorkingCopy(String contents) throws Exception {
|
||||
TextDocumentItem doc = new TextDocumentItem();
|
||||
doc.setLanguageId(getLanguageId());
|
||||
doc.setLanguageId(getDefaultLanguageId());
|
||||
doc.setText(contents);
|
||||
doc.setUri(createTempUri());
|
||||
doc.setVersion(getFirstVersion());
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DocumentEditsTest {
|
||||
}
|
||||
|
||||
private IDocument getFreshDocument(Editor editor) throws Exception {
|
||||
TextDocument doc = new TextDocument(null);
|
||||
TextDocument doc = new TextDocument(null, editor.getLanguageId());
|
||||
doc.setText(editor.getRawText());
|
||||
return doc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user