Cleanups: more type-checked representation of LanguageId
This commit is contained in:
@@ -24,6 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.ide.vscode.project.harness.PropertyIndexHarness;
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class ScopeCompletionTest {
|
||||
|
||||
|
||||
private final JavaProjectFinder javaProjectFinder = (doc) -> getTestProject();
|
||||
|
||||
private LanguageServerHarness harness;
|
||||
@@ -47,7 +48,7 @@ public class ScopeCompletionTest {
|
||||
public void setup() throws Exception {
|
||||
testProject = ProjectsHarness.INSTANCE.mavenProject("test-annotations");
|
||||
indexHarness = new PropertyIndexHarness();
|
||||
|
||||
|
||||
harness = new LanguageServerHarness(new Callable<BootJavaLanguageServer>() {
|
||||
@Override
|
||||
public BootJavaLanguageServer call() throws Exception {
|
||||
@@ -62,7 +63,7 @@ public class ScopeCompletionTest {
|
||||
};
|
||||
harness.intialize(null);
|
||||
}
|
||||
|
||||
|
||||
private IJavaProject getTestProject() {
|
||||
return testProject;
|
||||
}
|
||||
@@ -79,7 +80,7 @@ public class ScopeCompletionTest {
|
||||
"@Scope(\"application\"<*>)",
|
||||
"@Scope(\"websocket\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmptyStringLiteralCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(\"<*>\")");
|
||||
@@ -92,7 +93,7 @@ public class ScopeCompletionTest {
|
||||
"@Scope(\"application\"<*>)",
|
||||
"@Scope(\"websocket\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmptyValueCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(value=<*>)");
|
||||
@@ -105,7 +106,7 @@ public class ScopeCompletionTest {
|
||||
"@Scope(value=\"application\"<*>)",
|
||||
"@Scope(value=\"websocket\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmptyValueStringLiteralCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(value=\"<*>\")");
|
||||
@@ -118,54 +119,54 @@ public class ScopeCompletionTest {
|
||||
"@Scope(value=\"application\"<*>)",
|
||||
"@Scope(value=\"websocket\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPrefixWithClosingQuotesCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(\"pro<*>\")");
|
||||
assertAnnotationCompletions(
|
||||
"@Scope(\"prototype\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPrefixWithoutClosingQuotesCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(\"pro<*>)");
|
||||
assertAnnotationCompletions();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValuePrefixWithClosingQuotesCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(value=\"pro<*>\")");
|
||||
assertAnnotationCompletions(
|
||||
"@Scope(value=\"prototype\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValuePrefixWithoutClosingQuotesCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(value=\"pro<*>)");
|
||||
assertAnnotationCompletions();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPrefixReplaceRestCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(\"pro<*>something\")");
|
||||
assertAnnotationCompletions(
|
||||
"@Scope(\"prototype\"<*>)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDifferentMemberNameCompletion() throws Exception {
|
||||
prepareCase("@Scope(\"onClass\")", "@Scope(proxyName=\"<*>\")");
|
||||
assertAnnotationCompletions();
|
||||
}
|
||||
|
||||
|
||||
private void prepareCase(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception {
|
||||
InputStream resource = this.getClass().getResourceAsStream("/test-projects/test-annotations/src/main/java/org/test/TestScopeCompletion.java");
|
||||
String content = IOUtils.toString(resource);
|
||||
|
||||
|
||||
content = content.replace(selectedAnnotation, annotationStatementBeforeTest);
|
||||
editor = new Editor(harness, content, "java");
|
||||
editor = new Editor(harness, content, LanguageId.JAVA);
|
||||
}
|
||||
|
||||
|
||||
private void assertAnnotationCompletions(String... completedAnnotations) throws Exception {
|
||||
List<CompletionItem> completions = editor.getCompletions();
|
||||
int i = 0;
|
||||
@@ -174,9 +175,9 @@ public class ScopeCompletionTest {
|
||||
clonedEditor.apply(completions.get(i++));
|
||||
assertTrue(clonedEditor.getText().contains(expectedCompleted));
|
||||
}
|
||||
|
||||
|
||||
assertEquals(i, completions.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
|
||||
import org.springframework.ide.vscode.boot.java.completions.ValueCompletionProcessor;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
@@ -281,7 +282,7 @@ public class ValueCompletionTest {
|
||||
String content = IOUtils.toString(resource);
|
||||
|
||||
content = content.replace(selectedAnnotation, annotationStatementBeforeTest);
|
||||
editor = new Editor(harness, content, "java");
|
||||
editor = new Editor(harness, content, LanguageId.JAVA);
|
||||
}
|
||||
|
||||
private void assertAnnotationCompletions(String... completedAnnotations) throws Exception {
|
||||
|
||||
@@ -27,11 +27,11 @@ import org.springframework.ide.vscode.boot.metadata.types.TypeParser;
|
||||
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.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.FuzzyMap;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
public class CommonLanguageTools {
|
||||
@@ -55,7 +55,7 @@ public class CommonLanguageTools {
|
||||
} else {
|
||||
prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
|
||||
if (prop!=null) {
|
||||
TextDocument doc = new TextDocument(null, LanguageIds.PLAINTEXT);
|
||||
TextDocument doc = new TextDocument(null, LanguageId.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()));
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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";
|
||||
|
||||
}
|
||||
@@ -54,11 +54,11 @@ import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
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.languageserver.quickfix.Quickfix;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -145,7 +145,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
public void didOpen(DidOpenTextDocumentParams params) {
|
||||
TextDocumentItem docId = params.getTextDocument();
|
||||
String url = docId.getUri();
|
||||
String languageId = docId.getLanguageId();
|
||||
LanguageId languageId = LanguageId.of(docId.getLanguageId());
|
||||
int version = docId.getVersion();
|
||||
if (url!=null) {
|
||||
String text = params.getTextDocument().getText();
|
||||
@@ -192,12 +192,12 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
TrackedDocument doc = documents.get(url);
|
||||
if (doc==null) {
|
||||
Log.warn("Trying to get document ["+url+"] but it did not exists. Creating it with language-id 'plaintext'");
|
||||
doc = createDocument(url, LanguageIds.PLAINTEXT, 0, "");
|
||||
doc = createDocument(url, LanguageId.PLAINTEXT, 0, "");
|
||||
}
|
||||
return doc.getDocument();
|
||||
}
|
||||
|
||||
private synchronized TrackedDocument createDocument(String url, String languageId, int version, String text) {
|
||||
private synchronized TrackedDocument createDocument(String url, LanguageId languageId, int version, String text) {
|
||||
if (documents.get(url)!=null) {
|
||||
Log.warn("Creating document ["+url+"] but it already exists. Existing document discarded!");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface IDocument {
|
||||
int getLineOffset(int line) throws BadLocationException;
|
||||
void replace(int start, int len, String text) throws BadLocationException;
|
||||
String textBetween(int start, int end) throws BadLocationException;
|
||||
String getLanguageId();
|
||||
LanguageId getLanguageId();
|
||||
int getVersion();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* 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.util.text;
|
||||
|
||||
/**
|
||||
* Central place to define constants for the known language-ids that we care
|
||||
* about.
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
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 JAVA = of("java");
|
||||
public static final LanguageId YAML = of("yaml");
|
||||
|
||||
private final String id;
|
||||
|
||||
private LanguageId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LanguageId other = (LanguageId) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LanguageId ["+ id + "]";
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static LanguageId of(String languageId) {
|
||||
return new LanguageId(languageId);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,12 @@ 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 LanguageId languageId;
|
||||
private final String uri;
|
||||
private Text text = new Text("");
|
||||
private int version;
|
||||
|
||||
public TextDocument(String uri, String languageId) {
|
||||
public TextDocument(String uri, LanguageId languageId) {
|
||||
this(uri, languageId, 0, "");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TextDocument implements IDocument {
|
||||
this.version = other.version;
|
||||
}
|
||||
|
||||
public TextDocument(String uri, String languageId, int version, String text) {
|
||||
public TextDocument(String uri, LanguageId languageId, int version, String text) {
|
||||
this.uri = uri;
|
||||
this.languageId = languageId;
|
||||
this.version = version;
|
||||
@@ -274,7 +274,7 @@ public class TextDocument implements IDocument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageId() {
|
||||
public LanguageId getLanguageId() {
|
||||
return languageId;
|
||||
}
|
||||
|
||||
@@ -282,6 +282,7 @@ public class TextDocument implements IDocument {
|
||||
return toRange(region.getOffset(), region.getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.yaml.structure;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
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.YamlFileAST;
|
||||
@@ -55,8 +56,8 @@ class MockYamlEditor {
|
||||
return sp.getStructure(doc);
|
||||
}
|
||||
|
||||
protected String getLanguageId() {
|
||||
return "yaml";
|
||||
protected LanguageId getLanguageId() {
|
||||
return LanguageId.YAML;
|
||||
}
|
||||
|
||||
public YamlFileAST parse() throws Exception {
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -102,11 +103,11 @@ public class Editor {
|
||||
|
||||
private int selectionStart;
|
||||
private Set<String> ignoredTypes;
|
||||
private String languageId;
|
||||
private LanguageId languageId;
|
||||
|
||||
public Editor(LanguageServerHarness harness, String contents, String languageId) throws Exception {
|
||||
public Editor(LanguageServerHarness harness, String contents, LanguageId languageId) throws Exception {
|
||||
this.harness = harness;
|
||||
this.languageId = new String(languageId); // So we can catch bugs that use == for langauge id comparison.
|
||||
this.languageId = LanguageId.of(languageId.getId()); // So we can catch bugs that use == for langauge id comparison.
|
||||
EditorState state = new EditorState(contents);
|
||||
this.document = harness.openDocument(harness.createWorkingCopy(state.documentContents, this.languageId));
|
||||
this.selectionStart = state.selectionStart;
|
||||
@@ -651,7 +652,7 @@ public class Editor {
|
||||
return new Range(document.toPosition(start), document.toPosition(start+focusSnippet.length()));
|
||||
}
|
||||
|
||||
public String getLanguageId() {
|
||||
public LanguageId getLanguageId() {
|
||||
return languageId;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ import org.eclipse.lsp4j.WorkspaceClientCapabilites;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.services.LanguageClientAware;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
@@ -80,6 +79,7 @@ import org.springframework.ide.vscode.commons.languageserver.util.LanguageServer
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -94,7 +94,7 @@ public class LanguageServerHarness {
|
||||
private Random random = new Random();
|
||||
|
||||
private Callable<? extends SimpleLanguageServer> factory;
|
||||
private String defaultLanguageId;
|
||||
private LanguageId defaultLanguageId;
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
|
||||
@@ -105,13 +105,13 @@ public class LanguageServerHarness {
|
||||
private List<Editor> activeEditors = new ArrayList<>();
|
||||
|
||||
|
||||
public LanguageServerHarness(Callable<? extends SimpleLanguageServer> factory, String defaultLanguageId) {
|
||||
public LanguageServerHarness(Callable<? extends SimpleLanguageServer> factory, LanguageId defaultLanguageId) {
|
||||
this.factory = factory;
|
||||
this.defaultLanguageId = defaultLanguageId;
|
||||
}
|
||||
|
||||
public LanguageServerHarness(Callable<? extends SimpleLanguageServer> factory) throws Exception {
|
||||
this(factory, LanguageIds.PLAINTEXT);
|
||||
this(factory, LanguageId.PLAINTEXT);
|
||||
}
|
||||
|
||||
public synchronized TextDocumentInfo getOrReadFile(File file, String languageId) throws Exception {
|
||||
@@ -137,7 +137,7 @@ public class LanguageServerHarness {
|
||||
private synchronized TextDocumentItem setDocumentContent(String uri, String newContent) {
|
||||
TextDocumentInfo o = documents.get(uri);
|
||||
TextDocumentItem n = new TextDocumentItem();
|
||||
n.setLanguageId(o.getLanguageId());
|
||||
n.setLanguageId(o.getLanguageId().getId());
|
||||
n.setText(newContent);
|
||||
n.setVersion(o.getVersion()+1);
|
||||
n.setUri(o.getUri());
|
||||
@@ -149,7 +149,7 @@ public class LanguageServerHarness {
|
||||
return Charset.forName("utf8");
|
||||
}
|
||||
|
||||
protected String getDefaultLanguageId() {
|
||||
protected LanguageId getDefaultLanguageId() {
|
||||
return defaultLanguageId;
|
||||
}
|
||||
|
||||
@@ -397,15 +397,15 @@ public class LanguageServerHarness {
|
||||
return newEditor(getDefaultLanguageId(), contents);
|
||||
}
|
||||
|
||||
public synchronized Editor newEditor(String languageId, String contents) throws Exception {
|
||||
public synchronized Editor newEditor(LanguageId languageId, String contents) throws Exception {
|
||||
Editor editor = new Editor(this, contents, languageId);
|
||||
activeEditors.add(editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
public synchronized TextDocumentInfo createWorkingCopy(String contents, String languageId) throws Exception {
|
||||
public synchronized TextDocumentInfo createWorkingCopy(String contents, LanguageId languageId) throws Exception {
|
||||
TextDocumentItem doc = new TextDocumentItem();
|
||||
doc.setLanguageId(languageId);
|
||||
doc.setLanguageId(languageId.getId());
|
||||
doc.setText(contents);
|
||||
doc.setUri(createTempUri());
|
||||
doc.setVersion(getFirstVersion());
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.TextDocumentItem;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
|
||||
/**
|
||||
* Deprecated, we should get rid of this class and use {@link TextDocument}.
|
||||
@@ -37,8 +38,8 @@ public class TextDocumentInfo {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public String getLanguageId() {
|
||||
return getDocument().getLanguageId();
|
||||
public LanguageId getLanguageId() {
|
||||
return LanguageId.of(getDocument().getLanguageId());
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
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.VscodeHoverEngineAdapter;
|
||||
@@ -26,6 +25,7 @@ import org.springframework.ide.vscode.commons.languageserver.util.DocumentSymbol
|
||||
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.CollectionUtil;
|
||||
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.completion.SchemaBasedYamlAssistContextProvider;
|
||||
@@ -90,9 +90,9 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
// SimpleWorkspaceService workspace = getWorkspaceService();
|
||||
documents.onDidChangeContent(params -> {
|
||||
TextDocument doc = params.getDocument();
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
validateWith(doc.getId(), forPipelines.reconcileEngine);
|
||||
} else if (LanguageIds.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
} else if (LanguageId.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
validateWith(doc.getId(), forTasks.reconcileEngine);
|
||||
} else {
|
||||
validateWith(doc.getId(), IReconcileEngine.NULL);
|
||||
@@ -113,9 +113,9 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
documents.onCompletion(params -> {
|
||||
TextDocument doc = documents.get(params);
|
||||
if (doc!=null) {
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
return forPipelines.completionEngine.getCompletions(params);
|
||||
} else if (LanguageIds.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
} else if (LanguageId.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
return forTasks.completionEngine.getCompletions(params);
|
||||
}
|
||||
}
|
||||
@@ -129,9 +129,9 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
documents.onHover(params -> {
|
||||
TextDocument doc = documents.get(params);
|
||||
if (doc!=null) {
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
return forPipelines.hoverEngine.getHover(params);
|
||||
} else if (LanguageIds.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
} else if (LanguageId.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
return forTasks.hoverEngine.getHover(params);
|
||||
}
|
||||
}
|
||||
@@ -142,9 +142,9 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
DocumentSymbolHandler handler = DocumentSymbolHandler.NO_SYMBOLS;
|
||||
TextDocument doc = documents.getDocument(params.getTextDocument().getUri());
|
||||
if (doc!=null) {
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
handler = forPipelines.symbolHandler;
|
||||
} else if (LanguageIds.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
} else if (LanguageId.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
handler = forTasks.symbolHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.util.MimeTypes;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
@@ -25,6 +24,7 @@ import org.springframework.ide.vscode.commons.util.ValueParseException;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParsers;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST;
|
||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
|
||||
@@ -241,8 +241,8 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
addProp(task, "run", t_command).isRequired(true);
|
||||
addProp(task, "params", t_string_params);
|
||||
task.require((dc) -> {
|
||||
String languageId = dc.getDocument().getLanguageId();
|
||||
if (LanguageIds.CONCOURSE_PIPELINE.equals(languageId)) {
|
||||
LanguageId languageId = dc.getDocument().getLanguageId();
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(languageId)) {
|
||||
Node parentImageDef = models.getParentPropertyNode("image", dc);
|
||||
if (parentImageDef==null) {
|
||||
return Constraints.requireOneOf("image_resource", "image");
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
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.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.CodeAction;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
@@ -40,7 +40,7 @@ public class ConcourseEditorTest {
|
||||
return new ConcourseLanguageServer()
|
||||
.setMaxCompletions(100);
|
||||
},
|
||||
LanguageIds.CONCOURSE_PIPELINE
|
||||
LanguageId.CONCOURSE_PIPELINE
|
||||
);
|
||||
harness.intialize(null);
|
||||
}
|
||||
@@ -2492,12 +2492,12 @@ public class ConcourseEditorTest {
|
||||
@Test public void reconcileTaskFileToplevelProperties() throws Exception {
|
||||
Editor editor;
|
||||
|
||||
editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"image: some-image"
|
||||
);
|
||||
editor.assertProblems("image: some-image|[platform, run] are required");
|
||||
|
||||
editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"platform: a-platform\n" +
|
||||
"image_resource:\n" +
|
||||
" name: should-not-be-here\n" +
|
||||
@@ -2526,6 +2526,10 @@ public class ConcourseEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void reconcileTaskFileMissingToplevelProperties() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test public void contentAssistTaskFileToplevelProperties() throws Exception {
|
||||
assertTaskCompletions(
|
||||
"<*>"
|
||||
@@ -2560,7 +2564,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
@Test public void hoversForTaskFileToplevelProperties() throws Exception {
|
||||
Editor editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
Editor editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"image: some-image\n" +
|
||||
"image_resource:\n" +
|
||||
" type: docker-image\n" +
|
||||
@@ -2624,7 +2628,7 @@ public class ConcourseEditorTest {
|
||||
@Test public void taskRunPropertiesValidationAndHovers() throws Exception {
|
||||
Editor editor;
|
||||
|
||||
editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"inputs:\n" +
|
||||
"- name: sts4\n" +
|
||||
"outputs:\n" +
|
||||
@@ -2651,7 +2655,7 @@ public class ConcourseEditorTest {
|
||||
editor.assertHoverContains("dir", "A directory, relative to the initial working directory, to set as the working directory");
|
||||
editor.assertHoverContains("user", "Explicitly set the user to run as");
|
||||
|
||||
editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"inputs:\n" +
|
||||
"- name: sts4\n" +
|
||||
"outputs:\n" +
|
||||
@@ -2668,7 +2672,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
@Test public void nameAndPathHoversInTaskInputsAndOutputs() throws Exception {
|
||||
Editor editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
Editor editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"inputs:\n" +
|
||||
"- name: sts4\n" +
|
||||
" path: botk\n" +
|
||||
@@ -2798,7 +2802,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
@Test public void resourceInTaskConfigFileNotRequired() throws Exception {
|
||||
Editor editor = harness.newEditor(LanguageIds.CONCOURSE_TASK,
|
||||
Editor editor = harness.newEditor(LanguageId.CONCOURSE_TASK,
|
||||
"inputs:\n" +
|
||||
"- name: commons-git\n" +
|
||||
"platform: linux\n" +
|
||||
@@ -3120,7 +3124,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
private void assertTaskCompletions(String textBefore, String... textAfter) throws Exception {
|
||||
Editor editor = harness.newEditor(LanguageIds.CONCOURSE_TASK, textBefore);
|
||||
Editor editor = harness.newEditor(LanguageId.CONCOURSE_TASK, textBefore);
|
||||
editor.assertCompletions(textAfter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user