Search in sources :

Example 1 with LangServerFSProjectDirectory

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

the class TextDocumentServiceUtil method prepareCompilerContext.

/**
 * Prepare the compiler context.
 *
 * @param packageRepository  Package Repository
 * @param sourceRoot         LSDocument for Source Root
 * @param preserveWhitespace Preserve Whitespace
 * @return {@link CompilerContext}     Compiler context
 */
public static CompilerContext prepareCompilerContext(PackageRepository packageRepository, LSDocument sourceRoot, boolean preserveWhitespace, WorkspaceDocumentManager documentManager, CompilerPhase compilerPhase) {
    org.wso2.ballerinalang.compiler.util.CompilerContext context = new CompilerContext();
    context.put(PackageRepository.class, packageRepository);
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, sourceRoot.getSourceRoot());
    if (null == compilerPhase) {
        throw new AssertionError("Compiler Phase can not be null.");
    }
    options.put(COMPILER_PHASE, compilerPhase.toString());
    options.put(PRESERVE_WHITESPACE, Boolean.valueOf(preserveWhitespace).toString());
    if (isProjectDir(sourceRoot.getSourceRoot(), sourceRoot.getURIString())) {
        context.put(SourceDirectory.class, new LangServerFSProjectDirectory(sourceRoot.getSourceRootPath(), documentManager));
    } else {
        context.put(SourceDirectory.class, new LangServerFSProgramDirectory(sourceRoot.getSourceRootPath(), documentManager));
    }
    return context;
}
Also used : CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) LangServerFSProgramDirectory(org.ballerinalang.langserver.workspace.repository.LangServerFSProgramDirectory) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) LangServerFSProjectDirectory(org.ballerinalang.langserver.workspace.repository.LangServerFSProjectDirectory)

Aggregations

LangServerFSProgramDirectory (org.ballerinalang.langserver.workspace.repository.LangServerFSProgramDirectory)1 LangServerFSProjectDirectory (org.ballerinalang.langserver.workspace.repository.LangServerFSProjectDirectory)1 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)1 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)1