Make get rid of concourse ls simpelanguageserver subclassing
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.reconcile;
|
||||
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DiagnosticSeverityProvider {
|
||||
DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem);
|
||||
|
||||
static final DiagnosticSeverityProvider DEFAULT = (problem) -> {
|
||||
ProblemSeverity severity = problem.getType().getDefaultSeverity();
|
||||
switch (severity) {
|
||||
case ERROR:
|
||||
return DiagnosticSeverity.Error;
|
||||
case WARNING:
|
||||
return DiagnosticSeverity.Warning;
|
||||
case INFO:
|
||||
return DiagnosticSeverity.Information;
|
||||
case HINT:
|
||||
return DiagnosticSeverity.Hint;
|
||||
case IGNORE:
|
||||
return null;
|
||||
default:
|
||||
throw new IllegalStateException("Bug! Missing switch case?");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -69,6 +70,7 @@ import org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.Q
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixEdit;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixResolveParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
|
||||
@@ -108,7 +110,7 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
|
||||
public final String EXTENSION_ID;
|
||||
private final String CODE_ACTION_COMMAND_ID;
|
||||
protected final LazyCompletionResolver completionResolver = createCompletionResolver();
|
||||
public final LazyCompletionResolver completionResolver = createCompletionResolver();
|
||||
|
||||
private SimpleTextDocumentService tds;
|
||||
|
||||
@@ -510,6 +512,8 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
*/
|
||||
private Set<VersionedTextDocumentIdentifier> queuedReconcileRequests = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
private DiagnosticSeverityProvider severityProvider = DiagnosticSeverityProvider.DEFAULT;
|
||||
|
||||
/**
|
||||
* Convenience method. Subclasses can call this to use a {@link IReconcileEngine} ported
|
||||
* from old STS codebase to validate a given {@link TextDocument} and publish Diagnostics.
|
||||
@@ -607,22 +611,8 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
protected DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem) {
|
||||
ProblemSeverity severity = problem.getType().getDefaultSeverity();
|
||||
switch (severity) {
|
||||
case ERROR:
|
||||
return DiagnosticSeverity.Error;
|
||||
case WARNING:
|
||||
return DiagnosticSeverity.Warning;
|
||||
case INFO:
|
||||
return DiagnosticSeverity.Information;
|
||||
case HINT:
|
||||
return DiagnosticSeverity.Hint;
|
||||
case IGNORE:
|
||||
return null;
|
||||
default:
|
||||
throw new IllegalStateException("Bug! Missing switch case?");
|
||||
}
|
||||
public DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem) {
|
||||
return severityProvider.getDiagnosticSeverity(problem);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -694,4 +684,8 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
}
|
||||
return classpathListenerManager.addClasspathListener(classpathListener);
|
||||
}
|
||||
|
||||
public void setDiagnosticSeverityProvider(DiagnosticSeverityProvider severities) {
|
||||
this.severityProvider = severities;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,8 @@ public interface YamlCompletionEngineOptions {
|
||||
* some spaces in front of the cursor first.
|
||||
*/
|
||||
default boolean includeDeindentedProposals() {
|
||||
//Disabled by default for now because of bug introduced in VSCode 1.12:
|
||||
//https://github.com/Microsoft/vscode/issues/26096
|
||||
return true;
|
||||
}
|
||||
|
||||
YamlCompletionEngineOptions DEFAULT = new YamlCompletionEngineOptions() {};
|
||||
YamlCompletionEngineOptions TEST_DEFAULT = new YamlCompletionEngineOptions() {
|
||||
@Override public boolean includeDeindentedProposals() { return true; }
|
||||
};
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.languageserver.starter;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.ide.vscode.commons.languageserver.config.LanguageServerInitializer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.config.LanguageServerProperties;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
|
||||
@Configuration
|
||||
@@ -23,8 +26,13 @@ import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguage
|
||||
public class LanguageServerAutoConf {
|
||||
|
||||
@ConditionalOnMissingBean
|
||||
@Bean public SimpleLanguageServer languageServer(LanguageServerProperties props, LanguageServerInitializer initializer) throws Exception {
|
||||
@Bean public SimpleLanguageServer languageServer(
|
||||
LanguageServerProperties props,
|
||||
LanguageServerInitializer initializer,
|
||||
Optional<DiagnosticSeverityProvider> severities
|
||||
) throws Exception {
|
||||
SimpleLanguageServer server = new SimpleLanguageServer(props.getExtensionId());
|
||||
severities.ifPresent(server::setDiagnosticSeverityProvider);
|
||||
initializer.initialize(server);
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -51,9 +51,8 @@
|
||||
</dependency>
|
||||
<!-- Test harness -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>${mockito-version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -19,6 +18,7 @@ import java.util.Optional;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.definition.SimpleDefinitionFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
@@ -33,9 +33,7 @@ import org.yaml.snakeyaml.nodes.Node;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseLanguageServer> {
|
||||
public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<SimpleLanguageServer> {
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Handler {
|
||||
@@ -46,7 +44,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
private Map<YType, Handler> handlers = new HashMap<>();
|
||||
private final YamlAstCache asts;
|
||||
|
||||
public ConcourseDefinitionFinder(ConcourseLanguageServer server, ConcourseModel models, PipelineYmlSchema schema) {
|
||||
public ConcourseDefinitionFinder(SimpleLanguageServer server, ConcourseModel models, PipelineYmlSchema schema) {
|
||||
super(server);
|
||||
this.astTypes = models.getAstTypeCache();
|
||||
this.asts = models.getAstCache();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.concourse;
|
||||
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblem;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConcourseDiagnosticSeverities implements DiagnosticSeverityProvider {
|
||||
|
||||
@Override
|
||||
public DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem) {
|
||||
ProblemType type = problem.getType();
|
||||
if (YamlSchemaProblems.PROPERTY_CONSTRAINT.contains(type)) {
|
||||
return DiagnosticSeverity.Warning;
|
||||
}
|
||||
return DEFAULT.getDiagnosticSeverity(problem);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,8 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.ide.vscode.commons.util.LogRedirect;
|
||||
import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngineOptions;
|
||||
import org.springframework.ide.vscode.concourse.github.DefaultGithubInfoProvider;
|
||||
import org.springframework.ide.vscode.concourse.github.GithubInfoProvider;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ConcourseLanguageServerBootApp {
|
||||
@@ -31,7 +31,11 @@ public class ConcourseLanguageServerBootApp {
|
||||
return SERVER_NAME;
|
||||
}
|
||||
|
||||
@Bean ConcourseLanguageServer languageServer() {
|
||||
return new ConcourseLanguageServer(YamlCompletionEngineOptions.DEFAULT, new DefaultGithubInfoProvider());
|
||||
@Bean ConcourseLanguageServerInitializer languageServer(GithubInfoProvider github) {
|
||||
return new ConcourseLanguageServerInitializer(github);
|
||||
}
|
||||
|
||||
@Bean GithubInfoProvider github() {
|
||||
return new DefaultGithubInfoProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter;
|
||||
import org.springframework.ide.vscode.commons.languageserver.config.LanguageServerInitializer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.HoverInfoProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.VscodeHoverEngineAdapter;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
|
||||
@@ -40,21 +41,31 @@ import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
import org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator;
|
||||
import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider;
|
||||
import org.springframework.ide.vscode.concourse.github.GithubInfoProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
@Component
|
||||
public class ConcourseLanguageServerInitializer implements LanguageServerInitializer {
|
||||
|
||||
private final YamlCompletionEngineOptions COMPLETION_OPTIONS = YamlCompletionEngineOptions.DEFAULT;
|
||||
private final GithubInfoProvider github;
|
||||
private final YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT;
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
private ConcourseModel models;
|
||||
|
||||
private final YamlCompletionEngineOptions COMPLETION_OPTIONS;
|
||||
YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT;
|
||||
SimpleTextDocumentService documents = getTextDocumentService();
|
||||
ConcourseModel models = new ConcourseModel(this);
|
||||
YamlASTProvider currentAsts = models.getAstCache().getAstProvider(false);
|
||||
private SchemaSpecificPieces forPipelines;
|
||||
private SchemaSpecificPieces forTasks;
|
||||
private final YamlQuickfixes yamlQuickfixes;
|
||||
private YamlQuickfixes yamlQuickfixes;
|
||||
private YamlASTProvider currentAsts;
|
||||
|
||||
public ConcourseLanguageServerInitializer(GithubInfoProvider github) {
|
||||
this.github = github;
|
||||
}
|
||||
|
||||
private class SchemaSpecificPieces {
|
||||
|
||||
@@ -66,16 +77,16 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
SchemaSpecificPieces(YamlSchema schema, List<YType> definitionTypes) {
|
||||
SchemaBasedYamlAssistContextProvider contextProvider = new SchemaBasedYamlAssistContextProvider(schema);
|
||||
YamlCompletionEngine yamlCompletionEngine = new YamlCompletionEngine(structureProvider, contextProvider, COMPLETION_OPTIONS);
|
||||
this.completionEngine = createCompletionEngineAdapter(ConcourseLanguageServer.this, yamlCompletionEngine);
|
||||
this.completionEngine = server.createCompletionEngineAdapter(server, yamlCompletionEngine);
|
||||
|
||||
HoverInfoProvider infoProvider = new YamlHoverInfoProvider(currentAsts, structureProvider, contextProvider);
|
||||
this.hoverEngine = new VscodeHoverEngineAdapter(ConcourseLanguageServer.this, infoProvider);
|
||||
this.hoverEngine = new VscodeHoverEngineAdapter(server, infoProvider);
|
||||
|
||||
this.reconcileEngine = new YamlSchemaBasedReconcileEngine(currentAsts, schema, yamlQuickfixes);
|
||||
reconcileEngine.setTypeCollector(models.getAstTypeCache());
|
||||
|
||||
this.symbolHandler = CollectionUtil.hasElements(definitionTypes)
|
||||
? new TypeBasedYamlSymbolHandler(documents, models.getAstTypeCache(), definitionTypes)
|
||||
? new TypeBasedYamlSymbolHandler(server.getTextDocumentService(), models.getAstTypeCache(), definitionTypes)
|
||||
: DocumentSymbolHandler.NO_SYMBOLS;
|
||||
}
|
||||
|
||||
@@ -86,32 +97,36 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
public void enableSnippets(PipelineYmlSchema schema, boolean enable) {
|
||||
if (enable) {
|
||||
schema.f.setSnippetProvider(new SchemaBasedSnippetGenerator(schema.getTypeUtil(), this::createSnippetBuilder));
|
||||
schema.f.setSnippetProvider(new SchemaBasedSnippetGenerator(schema.getTypeUtil(), server::createSnippetBuilder));
|
||||
} else {
|
||||
schema.f.setSnippetProvider(null);
|
||||
}
|
||||
}
|
||||
|
||||
public ConcourseLanguageServer(YamlCompletionEngineOptions completionOptions, GithubInfoProvider github) {
|
||||
super("vscode-concourse");
|
||||
this.COMPLETION_OPTIONS = completionOptions;
|
||||
@Override
|
||||
public void initialize(SimpleLanguageServer server) throws Exception {
|
||||
Assert.isNull(this.server, "This initializer should only be used once");
|
||||
this.server = server;
|
||||
this.models = new ConcourseModel(server);
|
||||
this.currentAsts = models.getAstCache().getAstProvider(false);
|
||||
PipelineYmlSchema pipelineSchema = new PipelineYmlSchema(models, github);
|
||||
enableSnippets(pipelineSchema, true);
|
||||
this.yamlQuickfixes = new YamlQuickfixes(getQuickfixRegistry(), documents, structureProvider);
|
||||
SimpleTextDocumentService documents = server.getTextDocumentService();
|
||||
this.yamlQuickfixes = new YamlQuickfixes(server.getQuickfixRegistry(), documents, structureProvider);
|
||||
|
||||
this.forPipelines = new SchemaSpecificPieces(pipelineSchema, pipelineSchema.getDefinitionTypes());
|
||||
this.forTasks = new SchemaSpecificPieces(pipelineSchema.getTaskSchema(), null);
|
||||
ConcourseDefinitionFinder definitionFinder = new ConcourseDefinitionFinder(this, models, pipelineSchema);
|
||||
ConcourseDefinitionFinder definitionFinder = new ConcourseDefinitionFinder(server, models, pipelineSchema);
|
||||
|
||||
// SimpleWorkspaceService workspace = getWorkspaceService();
|
||||
documents.onDidChangeContent(params -> {
|
||||
TextDocument doc = params.getDocument();
|
||||
if (LanguageId.CONCOURSE_PIPELINE.equals(doc.getLanguageId())) {
|
||||
validateWith(doc.getId(), forPipelines.reconcileEngine);
|
||||
server.validateWith(doc.getId(), forPipelines.reconcileEngine);
|
||||
} else if (LanguageId.CONCOURSE_TASK.equals(doc.getLanguageId())) {
|
||||
validateWith(doc.getId(), forTasks.reconcileEngine);
|
||||
server.validateWith(doc.getId(), forTasks.reconcileEngine);
|
||||
} else {
|
||||
validateWith(doc.getId(), IReconcileEngine.NULL);
|
||||
server.validateWith(doc.getId(), IReconcileEngine.NULL);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -138,7 +153,7 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
return Mono.just(new CompletionList(false, ImmutableList.of()));
|
||||
});
|
||||
documents.onCompletionResolve(item -> {
|
||||
completionResolver.resolveNow(item);
|
||||
server.completionResolver.resolveNow(item);
|
||||
return item;
|
||||
});
|
||||
documents.onHover(params -> {
|
||||
@@ -167,18 +182,18 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem) {
|
||||
ProblemType type = problem.getType();
|
||||
if (YamlSchemaProblems.PROPERTY_CONSTRAINT.contains(type)) {
|
||||
return DiagnosticSeverity.Warning;
|
||||
}
|
||||
return super.getDiagnosticSeverity(problem);
|
||||
}
|
||||
public SimpleLanguageServer setMaxCompletions(int max) {
|
||||
// @Override
|
||||
// protected DiagnosticSeverity getDiagnosticSeverity(ReconcileProblem problem) {
|
||||
// ProblemType type = problem.getType();
|
||||
// if (YamlSchemaProblems.PROPERTY_CONSTRAINT.contains(type)) {
|
||||
// return DiagnosticSeverity.Warning;
|
||||
// }
|
||||
// return server.getDiagnosticSeverity(problem);
|
||||
// }
|
||||
|
||||
public void setMaxCompletions(int max) {
|
||||
forPipelines.setMaxCompletions(max);
|
||||
forTasks.setMaxCompletions(max);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
languageserver:
|
||||
extension-id: vscode-concourse
|
||||
@@ -30,39 +30,43 @@ import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.IOUtil;
|
||||
import org.springframework.ide.vscode.commons.util.Unicodes;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngineOptions;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
import org.springframework.ide.vscode.concourse.bootiful.ConcourseLanguageServerTest;
|
||||
import org.springframework.ide.vscode.concourse.github.GithubInfoProvider;
|
||||
import org.springframework.ide.vscode.concourse.github.GithubRepoContentAssistant;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.CodeAction;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.SynchronizationPoint;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ConcourseLanguageServerTest
|
||||
public class ConcourseEditorTest {
|
||||
|
||||
private static final YamlCompletionEngineOptions OPTIONS = YamlCompletionEngineOptions.TEST_DEFAULT;
|
||||
|
||||
private static final String CURSOR = "<*>";
|
||||
LanguageServerHarness<ConcourseLanguageServer> harness;
|
||||
|
||||
private GithubInfoProvider github= Mockito.mock(GithubInfoProvider.class);
|
||||
@Autowired
|
||||
ConcourseLanguageServerInitializer serverInitializer;
|
||||
|
||||
@Autowired
|
||||
LanguageServerHarness<SimpleLanguageServer> harness;
|
||||
|
||||
@MockBean
|
||||
private GithubInfoProvider github;
|
||||
|
||||
@Before public void setup() throws Exception {
|
||||
harness = new LanguageServerHarness<>(() -> {
|
||||
ConcourseLanguageServer s = new ConcourseLanguageServer(OPTIONS, github);
|
||||
s.setMaxCompletions(100);
|
||||
return s;
|
||||
},
|
||||
LanguageId.CONCOURSE_PIPELINE
|
||||
);
|
||||
serverInitializer.setMaxCompletions(100);
|
||||
harness.intialize(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,21 +21,21 @@ import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.ide.vscode.concourse.ConcourseLanguageServer;
|
||||
import org.springframework.ide.vscode.concourse.ConcourseLanguageServerInitializer;
|
||||
import org.springframework.ide.vscode.concourse.github.GithubInfoProvider;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import static org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngineOptions.*;
|
||||
|
||||
public class ConcourseLanguageServerTest {
|
||||
public class ConcourseLanguageServerInitializerTest {
|
||||
|
||||
public static File getTestResource(String name) throws URISyntaxException {
|
||||
return Paths.get(ConcourseLanguageServerTest.class.getResource(name).toURI()).toFile();
|
||||
return Paths.get(ConcourseLanguageServerInitializerTest.class.getResource(name).toURI()).toFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAndInitializeServerWithWorkspace() throws Exception {
|
||||
LanguageServerHarness harness = new LanguageServerHarness(() ->
|
||||
new ConcourseLanguageServer(TEST_DEFAULT, Mockito.mock(GithubInfoProvider.class)));
|
||||
new ConcourseLanguageServerInitializer(Mockito.mock(GithubInfoProvider.class)));
|
||||
File workspaceRoot = getTestResource("/workspace/");
|
||||
assertExpectedInitResult(harness.intialize(workspaceRoot));
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ConcourseLanguageServerTest {
|
||||
public void createAndInitializeServerWithoutWorkspace() throws Exception {
|
||||
File workspaceRoot = null;
|
||||
LanguageServerHarness harness = new LanguageServerHarness(() ->
|
||||
new ConcourseLanguageServer(TEST_DEFAULT, Mockito.mock(GithubInfoProvider.class)));
|
||||
new ConcourseLanguageServerInitializer(Mockito.mock(GithubInfoProvider.class)));
|
||||
assertExpectedInitResult(harness.intialize(workspaceRoot));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.concourse.bootiful;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.ide.vscode.concourse.ConcourseLanguageServerBootApp;
|
||||
import org.springframework.ide.vscode.languageserver.starter.LanguageServerAutoConf;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@OverrideAutoConfiguration(enabled=false)
|
||||
@ImportAutoConfiguration(classes=LanguageServerAutoConf.class)
|
||||
@SpringBootTest(classes={
|
||||
ConcourseLanguageServerBootApp.class,
|
||||
ConcourseLanguageServerTestConfiguration.class
|
||||
})
|
||||
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public @interface ConcourseLanguageServerTest {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.concourse.bootiful;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
|
||||
@Configuration
|
||||
public class ConcourseLanguageServerTestConfiguration {
|
||||
|
||||
@Bean public LanguageServerHarness<SimpleLanguageServer> harness(SimpleLanguageServer server) throws Exception {
|
||||
LanguageServerHarness<SimpleLanguageServer> harness = new LanguageServerHarness<>(
|
||||
()-> server,
|
||||
LanguageId.CONCOURSE_PIPELINE
|
||||
);
|
||||
return harness;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.main.banner-mode=off
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -54,6 +55,12 @@ public class ManifestYamlEditorTest {
|
||||
@Autowired
|
||||
LanguageServerHarness<SimpleLanguageServer> harness;
|
||||
|
||||
@Before
|
||||
public void initHarness() throws Exception {
|
||||
harness.intialize(null);
|
||||
System.setProperty("lsp.yaml.completions.errors.disable", "false"); //Yuck! Do we really need this??
|
||||
}
|
||||
|
||||
@Test public void testReconcileCatchesParseError() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"somemap: val\n"+
|
||||
|
||||
@@ -27,24 +27,31 @@ import org.eclipse.lsp4j.DidChangeConfigurationParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFClientParams;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServerWrapper;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.manifest.yaml.bootiful.ManifestLanguageServerTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ManifestLanguageServerTest
|
||||
public class ManifestYamlLanguageServerInitializerTest {
|
||||
|
||||
public static File getTestResource(String name) throws URISyntaxException {
|
||||
return Paths.get(ManifestYamlLanguageServerInitializerTest.class.getResource(name).toURI()).toFile();
|
||||
}
|
||||
|
||||
@Autowired LanguageServerHarness<SimpleLanguageServer> harness;
|
||||
@Autowired ManifestYamlLanguageServerInitializer serverInitializer;
|
||||
@Autowired SimpleLanguageServer server;
|
||||
|
||||
@Test
|
||||
public void createAndInitializeServerWithWorkspace() throws Exception {
|
||||
LanguageServerHarness<SimpleLanguageServer> harness = LanguageServerHarness.create("vscode-manifest-yaml", new ManifestYamlLanguageServerInitializer());
|
||||
File workspaceRoot = getTestResource("/workspace/");
|
||||
assertExpectedInitResult(harness.intialize(workspaceRoot));
|
||||
}
|
||||
@@ -52,7 +59,6 @@ public class ManifestYamlLanguageServerInitializerTest {
|
||||
@Test
|
||||
public void createAndInitializeServerWithoutWorkspace() throws Exception {
|
||||
File workspaceRoot = null;
|
||||
LanguageServerHarness<SimpleLanguageServer> harness = LanguageServerHarness.create("vscode-manifest-yaml", new ManifestYamlLanguageServerInitializer());
|
||||
assertExpectedInitResult(harness.intialize(workspaceRoot));
|
||||
}
|
||||
|
||||
@@ -93,16 +99,8 @@ public class ManifestYamlLanguageServerInitializerTest {
|
||||
assertThat(initResult.getCapabilities().getTextDocumentSync().getLeft()).isEqualTo(TextDocumentSyncKind.Incremental);
|
||||
}
|
||||
|
||||
@Test public void changeCfClientParams() throws Exception {
|
||||
MockCloudfoundry cloudfoundry = new MockCloudfoundry();
|
||||
ManifestYamlLanguageServerInitializer serverInitializer = new ManifestYamlLanguageServerInitializer(cloudfoundry.factory, cloudfoundry.defaultParamsProvider);
|
||||
SimpleLanguageServer server = new SimpleLanguageServer("vscode-manifest-yaml");
|
||||
serverInitializer.initialize(server);
|
||||
|
||||
LanguageServerHarness<SimpleLanguageServer> harness = new LanguageServerHarness<>(
|
||||
() -> server,
|
||||
LanguageId.CF_MANIFEST
|
||||
);
|
||||
@Test public void changeCfClientParams() throws Exception {
|
||||
harness.intialize(null);
|
||||
|
||||
// This is an initial target, for example from cf CLI
|
||||
|
||||
@@ -39,8 +39,6 @@ public class ManifestYamlLanguageServerTestConfiguration {
|
||||
()-> server,
|
||||
LanguageId.CF_MANIFEST
|
||||
);
|
||||
harness.intialize(null);
|
||||
System.setProperty("lsp.yaml.completions.errors.disable", "false"); //Yuck! Do we really need this??
|
||||
return harness;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user