Skip to content

Commit

Permalink
Sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeeshaan committed Jan 27, 2020
2 parents 80c4306 + b577044 commit b4aa67a
Show file tree
Hide file tree
Showing 180 changed files with 919 additions and 805 deletions.
1 change: 1 addition & 0 deletions distribution/zip/jballerina-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ dependencies {
dist project(':ballerina-backend-jvm')
birJar project(path: ':ballerina-backend-jvm', configuration: 'birJar')
dist project(':language-server:language-server-compiler')
dist project(':language-server:language-server-commons')
dist project(':ballerina-packerina')
dist project(':openapi-ballerina:ballerina-to-openapi-generator')
dist project(':openapi-ballerina:openapi-to-ballerina-generator')
Expand Down
1 change: 1 addition & 0 deletions distribution/zip/nballerina-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ dependencies {
dist project(':ballerina-backend-llvm')
birJar project(path: ':ballerina-backend-llvm', configuration: 'birJar')
dist project(':language-server:language-server-compiler')
dist project(':language-server:language-server-commons')
dist project(':ballerina-packerina')
dist project(':docerina')
docerina project(':docerina-gradle-plugin')
Expand Down
34 changes: 34 additions & 0 deletions language-server/modules/langserver-commons/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

apply from: "$rootDir/gradle/javaProject.gradle"

dependencies {
// NOTE: This module intended to be used by extension providers with minimum peer dependencies
// Thus, refrain from adding extra dependencies.
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j'
testCompile 'org.testng:testng'
}

description = 'Ballerina - Language server - Commons'

test {
exclude '**/*'
useTestNG() {
suites 'src/test/resources/testng.xml'
}
}
20 changes: 20 additions & 0 deletions language-server/modules/langserver-commons/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<FindBugsFilter>

</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.langserver.compiler;
package org.ballerinalang.langserver.commons;

/**
* Ballerina Language server context.
Expand Down Expand Up @@ -50,7 +50,7 @@ protected LSContext(LSOperation operation) {
*
* @return operation name
*/
LSOperation getOperation() {
public LSOperation getOperation() {
return this.operation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.langserver.compiler;
package org.ballerinalang.langserver.commons;

/**
* Ballerina Language server operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.codeaction;
package org.ballerinalang.langserver.commons.codeaction;

/**
* Represents the Code Action Node Type.
Expand All @@ -37,7 +37,7 @@ public enum CodeActionNodeType {
*/
public static CodeActionNodeType getNodeTypeByName(String name) {
for (CodeActionNodeType codeActionNodeType : CodeActionNodeType.values()) {
if (codeActionNodeType.name().equals(name)) {
if (name.equals(codeActionNodeType.name())) {
return codeActionNodeType;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,57 +13,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.codeaction;
package org.ballerinalang.langserver.commons.codeaction.spi;

import org.ballerinalang.langserver.compiler.LSContext;
import org.ballerinalang.langserver.commons.LSContext;
import org.ballerinalang.langserver.commons.codeaction.CodeActionNodeType;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;

import java.util.ArrayList;
import java.util.List;

/**
* Represents the SPI interface for the Ballerina Code Action Provider.
*
* @since 1.1.1
* @since 1.2.0
*/
public abstract class BallerinaCodeActionProvider {
List<CodeActionNodeType> codeActionNodeTypes;
private boolean isNodeBased = true;

public BallerinaCodeActionProvider() {
this(new ArrayList<>());
this.isNodeBased = false;
}

/**
* @param nodeTypes code action node types list
*/
public BallerinaCodeActionProvider(List<CodeActionNodeType> nodeTypes) {
this.codeActionNodeTypes = nodeTypes;
}

public interface LSCodeActionProvider {
/**
* returns the list of code actions based on node type or diagnostics.
* Returns the list of code actions based on node type or diagnostics.
*
* @param nodeType code action node type
* @param lsContext language server context
* @param diagnostics diagnostics list
* @return list of Code Actions
*/
protected abstract List<CodeAction> getCodeActions(CodeActionNodeType nodeType, LSContext lsContext,
List<Diagnostic> diagnostics);
List<CodeAction> getCodeActions(CodeActionNodeType nodeType, LSContext lsContext, List<Diagnostic> diagnostics);

protected final boolean isNodeBased() {
return this.isNodeBased;
}
/**
* Returns True of node type based code actions are supported.
* @return True of node type based code actions are supported, False otherwise
*/
boolean isNodeBasedSupported();

/**
* Returns True of code diagnostics type based code actions are supported.
* @return True of code diagnostics based code actions are supported, False otherwise
*/
boolean isDiagBasedSupported();

/**
* returns the list of node types that the code action belongs to.
*
* @return list of code action node type
*/
protected final List<CodeActionNodeType> getCodeActionNodeTypes() {
return this.codeActionNodeTypes;
}
List<CodeActionNodeType> getCodeActionNodeTypes();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.codelenses;
package org.ballerinalang.langserver.commons.codelenses;

/**
* Exception for Language Server Code Lenses.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.codelenses;
package org.ballerinalang.langserver.commons.codelenses.spi;

import org.ballerinalang.langserver.compiler.LSContext;
import org.ballerinalang.langserver.commons.LSContext;
import org.ballerinalang.langserver.commons.codelenses.LSCodeLensesProviderException;
import org.eclipse.lsp4j.CodeLens;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.command;
package org.ballerinalang.langserver.commons.command;

/**
* Exception for Language Server Command Execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.command;
package org.ballerinalang.langserver.commons.command.spi;

import org.ballerinalang.langserver.compiler.LSContext;
import org.ballerinalang.langserver.commons.LSContext;
import org.ballerinalang.langserver.commons.command.LSCommandExecutorException;

/**
* Represents the SPI interface for the Language Server Command Executor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ballerinalang.langserver.completions;
package org.ballerinalang.langserver.commons.completion;

/**
* This Exception is thrown when an error occurs during the completions process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.langserver;
package org.ballerinalang.langserver.commons.completion;

import org.eclipse.lsp4j.CompletionItem;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.langserver.commons.completion.spi;

import org.ballerinalang.langserver.commons.LSContext;
import org.ballerinalang.langserver.commons.completion.LSCompletionException;
import org.ballerinalang.langserver.commons.completion.LSCompletionItem;

import java.util.List;
import java.util.Optional;

/**
* Interface for completion item providers.
*
* @since 1.2.0
*/
public interface LSCompletionProvider {

/**
* Precedence for a given provider.
*
* @since 1.0
*/
enum Precedence {
LOW,
HIGH
}

/**
* Get Completion items for the scope/ context.
*
* @param context Language Server Context
* @return {@link List} List of calculated Completion Items
* @throws LSCompletionException when completion fails
*/
List<LSCompletionItem> getCompletions(LSContext context) throws LSCompletionException;

/**
* Get the attachment points where the current provider attached to.
*
* @return {@link List} List of attachment points
*/
List<Class> getAttachmentPoints();

/**
* Get the precedence of the provider.
*
* @return {@link Precedence} precedence of the provider
*/
Precedence getPrecedence();

/**
* Get the Context Provider.
* Ex: When a given scope is resolved then the context can be resolved by parsing a sub rule or token analyzing
*
* @param ctx Language Server Context
* @return {@link Optional} Context Completion provider
*/
Optional<LSCompletionProvider> getContextProvider(LSContext ctx);
}
1 change: 1 addition & 0 deletions language-server/modules/langserver-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ configurations.all {
}

dependencies {
implementation project(':language-server:language-server-commons')
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j'
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc'
implementation 'com.google.code.findbugs:jsr305'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.ballerinalang.langserver.compiler;

import org.ballerinalang.langserver.commons.LSOperation;

/**
* Represents Compile File operations in language server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.ballerinalang.langserver.compiler;

import org.ballerinalang.langserver.commons.LSContext;
import org.ballerinalang.langserver.compiler.common.LSDocument;
import org.ballerinalang.langserver.compiler.workspace.WorkspaceDocumentManager;
import org.ballerinalang.model.elements.PackageID;
Expand Down
Loading

0 comments on commit b4aa67a

Please sign in to comment.