use of org.ballerinalang.langserver.workspace.repository.LangServerFSProgramDirectory 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;
}
Aggregations