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;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.ide.vscode.boot.metadata.types.TypeUtil;
|
||||
import org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode;
|
||||
import org.springframework.ide.vscode.boot.metadata.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DocumentRegion;
|
||||
import org.springframework.ide.vscode.commons.util.CollectionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
@@ -54,7 +55,7 @@ public class CommonLanguageTools {
|
||||
} else {
|
||||
prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
|
||||
if (prop!=null) {
|
||||
TextDocument doc = new TextDocument(null);
|
||||
TextDocument doc = new TextDocument(null, LanguageIds.PLAINTEXT);
|
||||
doc.setText(propertyName);
|
||||
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
|
||||
return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
|
||||
|
||||
@@ -14,6 +14,7 @@ import {TextDocument, OutputChannel} from 'vscode';
|
||||
var log_output : OutputChannel = null;
|
||||
|
||||
const PIPELINE_LANGUAGE_ID = "concourse-pipeline-yaml";
|
||||
const TASK_LANGUAGE_ID = "concourse-task-yaml";
|
||||
|
||||
function log(msg : string) {
|
||||
if (log_output) {
|
||||
@@ -35,21 +36,12 @@ export function activate(context: VSCode.ExtensionContext) {
|
||||
extensionId: 'vscode-concourse',
|
||||
fatJarFile: 'target/vscode-concourse-0.0.1-SNAPSHOT.jar',
|
||||
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: [ PIPELINE_LANGUAGE_ID ],
|
||||
synchronize: {
|
||||
// TODO: Remove textDocumentFilter property once https://github.com/Microsoft/vscode-languageserver-node/issues/9 is resolved
|
||||
textDocumentFilter: function(textDocument : TextDocument) : boolean {
|
||||
let result : boolean = PIPELINE_LANGUAGE_ID===textDocument.languageId;
|
||||
// old way: let result : boolean = /^(.*)pipeline(.*)\.yml$/i.test(textDocument.fileName);
|
||||
return result;
|
||||
let languageId = textDocument.languageId;
|
||||
return PIPELINE_LANGUAGE_ID===languageId || TASK_LANGUAGE_ID===languageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,18 +24,38 @@
|
||||
"pipeline.yml"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:concourse-pipeline-yaml"
|
||||
"onLanguage:concourse-pipeline-yaml",
|
||||
"onLanguage:concourse-task-yaml"
|
||||
],
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "concourse-pipeline-yaml",
|
||||
"aliases": [
|
||||
"concourse-pipeline"
|
||||
"Concourse Pipeline"
|
||||
],
|
||||
"extensions": [
|
||||
".yml"
|
||||
],
|
||||
"filenamePatterns": [
|
||||
"*pipeline*.yml"
|
||||
],
|
||||
"firstLine": "^#(\\s)*pipeline(\\s)*",
|
||||
"configuration": "./yaml-support/language-configuration.json"
|
||||
},
|
||||
{
|
||||
"id": "concourse-task-yaml",
|
||||
"aliases": [
|
||||
"Concourse Task"
|
||||
],
|
||||
"extensions": [
|
||||
".yml"
|
||||
],
|
||||
"filenamePatterns": [
|
||||
"*task*.yml",
|
||||
"**/tasks/*.yml"
|
||||
],
|
||||
"firstLine": "^#(\\s)*task(\\s)*",
|
||||
"configuration": "./yaml-support/language-configuration.json"
|
||||
}
|
||||
],
|
||||
@@ -43,6 +63,10 @@
|
||||
"language": "concourse-pipeline-yaml",
|
||||
"scopeName": "source.yaml",
|
||||
"path": "./yaml-support/yaml.tmLanguage"
|
||||
}, {
|
||||
"language": "concourse-task-yaml",
|
||||
"scopeName": "source.yaml",
|
||||
"path": "./yaml-support/yaml.tmLanguage"
|
||||
}]
|
||||
},
|
||||
"main": "./out/lib/Main",
|
||||
|
||||
@@ -13,11 +13,13 @@ package org.springframework.ide.vscode.concourse;
|
||||
import org.eclipse.lsp4j.CompletionOptions;
|
||||
import org.eclipse.lsp4j.ServerCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.HoverInfoProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.VscodeHoverEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.VscodeHoverEngineAdapter;
|
||||
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.TextDocument;
|
||||
@@ -44,14 +46,22 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
VscodeCompletionEngine completionEngine = new VscodeCompletionEngineAdapter(this, yamlCompletionEngine);
|
||||
HoverInfoProvider infoProvider = new YamlHoverInfoProvider(currentAsts, structureProvider, contextProvider);
|
||||
VscodeHoverEngine hoverEngine = new VscodeHoverEngineAdapter(this, infoProvider);
|
||||
YamlSchemaBasedReconcileEngine reconcileEngine = new YamlSchemaBasedReconcileEngine(currentAsts, schema);
|
||||
|
||||
YamlSchemaBasedReconcileEngine pipelineReconcileEngine = new YamlSchemaBasedReconcileEngine(currentAsts, schema);
|
||||
pipelineReconcileEngine.setTypeCollector(models.getAstTypeCache());
|
||||
YamlSchemaBasedReconcileEngine taskReconcileEngine = new YamlSchemaBasedReconcileEngine(currentAsts, schema.getTaskSchema());
|
||||
ConcourseDefinitionFinder definitionFinder = new ConcourseDefinitionFinder(this, models, schema);
|
||||
reconcileEngine.setTypeCollector(models.getAstTypeCache());
|
||||
|
||||
// SimpleWorkspaceService workspace = getWorkspaceService();
|
||||
documents.onDidChangeContent(params -> {
|
||||
TextDocument doc = params.getDocument();
|
||||
validateWith(doc, reconcileEngine);
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
validateWith(doc, pipelineReconcileEngine);
|
||||
} else if (LanguageIds.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
validateWith(doc, taskReconcileEngine);
|
||||
} else {
|
||||
validateWith(doc, IReconcileEngine.NULL);
|
||||
}
|
||||
});
|
||||
|
||||
// workspace.onDidChangeConfiguraton(settings -> {
|
||||
|
||||
@@ -66,7 +66,6 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
.collect(Collectors.toSet())
|
||||
.block();
|
||||
|
||||
|
||||
private final YBeanType TOPLEVEL_TYPE;
|
||||
private final YTypeUtil TYPE_UTIL;
|
||||
|
||||
@@ -95,6 +94,8 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
public final YAtomicType t_job_name;
|
||||
public final YAtomicType t_resource_type_name;
|
||||
|
||||
public final YBeanType task;
|
||||
|
||||
private final ResourceTypeRegistry resourceTypes = new ResourceTypeRegistry();
|
||||
|
||||
public PipelineYmlSchema(ConcourseModel models) {
|
||||
@@ -237,6 +238,10 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
addProp(TOPLEVEL_TYPE, "resource_types", f.yseq(resourceType));
|
||||
addProp(TOPLEVEL_TYPE, "groups", f.yseq(group));
|
||||
|
||||
task = f.ybean("TaskConfig");
|
||||
YType t_platform = f.yenum("Platform", "windows", "linux", "darwin");
|
||||
addProp(task, "platform", t_platform);
|
||||
|
||||
initializeDefaultResourceTypes();
|
||||
}
|
||||
|
||||
@@ -381,4 +386,24 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
public YTypeUtil getTypeUtil() {
|
||||
return TYPE_UTIL;
|
||||
}
|
||||
|
||||
public YamlSchema getTaskSchema() {
|
||||
return new YamlSchema() {
|
||||
|
||||
@Override
|
||||
public YTypeUtil getTypeUtil() {
|
||||
return TYPE_UTIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YType getTopLevelType() {
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskYamlSchema";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,18 @@ import java.util.stream.Collectors;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.util.IOUtil;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
|
||||
public class PipelineYamlEditorTest {
|
||||
public class ConcourseEditorTest {
|
||||
|
||||
private static final String CURSOR = "<*>";
|
||||
LanguageServerHarness harness;
|
||||
|
||||
@Before public void setup() throws Exception {
|
||||
harness = new LanguageServerHarness(ConcourseLanguageServer::new);
|
||||
harness = new LanguageServerHarness(ConcourseLanguageServer::new, LanguageIds.CONCOURSE_PIPELINE);
|
||||
harness.intialize(null);
|
||||
}
|
||||
|
||||
@@ -45,9 +46,6 @@ public class PipelineYamlEditorTest {
|
||||
}
|
||||
|
||||
@Test public void reconcileRunsOnDocumentOpenAndChange() throws Exception {
|
||||
LanguageServerHarness harness = new LanguageServerHarness(ConcourseLanguageServer::new);
|
||||
harness.intialize(null);
|
||||
|
||||
Editor editor = harness.newEditor(
|
||||
"somemap: val\n"+
|
||||
"- sequence"
|
||||
@@ -90,7 +88,7 @@ public class PipelineYamlEditorTest {
|
||||
}
|
||||
|
||||
private String getClasspathResourceText(String resourceName) throws Exception {
|
||||
InputStream stream = PipelineYamlEditorTest.class.getClassLoader().getResourceAsStream(resourceName);
|
||||
InputStream stream = ConcourseEditorTest.class.getClassLoader().getResourceAsStream(resourceName);
|
||||
return IOUtil.toString(stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user