Search in sources :

Example 1 with WorkspaceDocumentManagerImpl

use of org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl in project ballerina by ballerina-lang.

the class CompletionTestUtil method prepareDocumentManager.

/**
 * Prepare the Document manager instance with the given file and issue the did open operation.
 *
 * @param uri        File Uri
 * @param balContent File Content
 * @return {@link WorkspaceDocumentManagerImpl}
 */
public static WorkspaceDocumentManagerImpl prepareDocumentManager(String uri, String balContent) {
    Path openedPath;
    WorkspaceDocumentManagerImpl documentManager = WorkspaceDocumentManagerImpl.getInstance();
    openedPath = Paths.get(uri);
    documentManager.openFile(openedPath, balContent);
    return documentManager;
}
Also used : Path(java.nio.file.Path) WorkspaceDocumentManagerImpl(org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl)

Example 2 with WorkspaceDocumentManagerImpl

use of org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl in project ballerina by ballerina-lang.

the class CompletionTest method test.

// @Test(dataProvider = "completion-data-provider")
public void test(String config, String configPath) {
    String configJsonPath = SAMPLES_COPY_DIR + File.separator + configPath + File.separator + config;
    JsonObject jsonObject = FileUtils.fileContentAsObject(configJsonPath);
    JsonArray expectedItems = jsonObject.get("items").getAsJsonArray();
    JsonObject positionObj = jsonObject.get("position").getAsJsonObject();
    String balPath = SAMPLES_COPY_DIR + File.separator + jsonObject.get("source").getAsString();
    Position position = new Position();
    String content = FileUtils.fileContent(balPath);
    position.setLine(positionObj.get("line").getAsInt());
    position.setCharacter(positionObj.get("character").getAsInt());
    TextDocumentPositionParams positionParams = CompletionTestUtil.getPositionParams(position, balPath);
    WorkspaceDocumentManagerImpl documentManager = CompletionTestUtil.prepareDocumentManager(balPath, content);
    List<CompletionItem> responseItemList = CompletionTestUtil.getCompletions(documentManager, positionParams);
    List<CompletionItem> expectedList = CompletionTestUtil.getExpectedItemList(expectedItems);
    Assert.assertEquals(true, CompletionTestUtil.isSubList(expectedList, responseItemList));
}
Also used : JsonArray(com.google.gson.JsonArray) WorkspaceDocumentManagerImpl(org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) JsonObject(com.google.gson.JsonObject) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Aggregations

WorkspaceDocumentManagerImpl (org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Path (java.nio.file.Path)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 Position (org.eclipse.lsp4j.Position)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1