public class LSCompilerUtil extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
EXPERIMENTAL_FEATURES_ENABLED |
static String |
UNTITLED_BAL |
Constructor and Description |
---|
LSCompilerUtil() |
Modifier and Type | Method and Description |
---|---|
static Path |
createTempFile(String tempFileId)
Create and returns temp file.
|
static String |
findProjectRoot(String parentDir)
Find project root directory.
|
static String |
findProjectRoot(String parentDir,
Path balHomePath) |
static Compiler |
getCompiler(LSContext context,
String relativeFilePath,
CompilerContext compilerContext,
Class customErrorStrategy)
Get compiler for the given context and file.
|
static Path |
getCurrentModulePath(Path filePath)
Returns top-level module path of a given file path.
|
static String |
getPackageNameForGivenFile(String sourceRoot,
String filePath)
Get the package name for given file.
|
static String |
getProjectDir(Path filePath)
Get the project dir for given file.
|
static String |
getSourceRoot(Path filePath)
Get the source root for the given package.
|
static Optional<String> |
getUntitledFileId(String filePath)
Returns unsaved file id or null.
|
static Optional<Path> |
getUntitledFilePath(String filePath)
Returns unsaved file path.
|
static boolean |
isBallerinaProject(String root,
String fileUri)
Check whether given directory is a project dir.
|
static CompilerContext |
prepareCompilerContext(PackageID packageID,
PackageRepository packageRepository,
LSDocument sourceRoot,
boolean preserveWhitespace,
WorkspaceDocumentManager documentManager)
Prepare the compiler context.
|
static CompilerContext |
prepareCompilerContext(PackageID packageID,
PackageRepository packageRepository,
LSDocument document,
boolean preserveWhitespace,
WorkspaceDocumentManager documentManager,
CompilerPhase compilerPhase)
Prepare the compiler context.
|
public static final String UNTITLED_BAL
public static final boolean EXPERIMENTAL_FEATURES_ENABLED
public static CompilerContext prepareCompilerContext(PackageID packageID, PackageRepository packageRepository, LSDocument sourceRoot, boolean preserveWhitespace, WorkspaceDocumentManager documentManager)
packageID
- Package NamepackageRepository
- Package RepositorysourceRoot
- LSDocument for Source RootpreserveWhitespace
- Preserve WhitespacedocumentManager
- WorkspaceDocumentManager
Document ManagerCompilerContext
Compiler contextpublic static CompilerContext prepareCompilerContext(PackageID packageID, PackageRepository packageRepository, LSDocument document, boolean preserveWhitespace, WorkspaceDocumentManager documentManager, CompilerPhase compilerPhase)
packageID
- Package IDpackageRepository
- Package Repositorydocument
- LSDocument for Source RootpreserveWhitespace
- Preserve WhitespacedocumentManager
- WorkspaceDocumentManager
Document ManagercompilerPhase
- CompilerPhase
Compiler PhaseCompilerContext
Compiler contextpublic static String findProjectRoot(String parentDir)
parentDir
- current parent directoryString
project root | null@CheckForNull public static String findProjectRoot(String parentDir, Path balHomePath)
public static Compiler getCompiler(LSContext context, String relativeFilePath, CompilerContext compilerContext, Class customErrorStrategy)
context
- Language server contextrelativeFilePath
- File name which is currently opencompilerContext
- Compiler contextcustomErrorStrategy
- custom error strategy classCompiler
ballerina compilerpublic static String getSourceRoot(Path filePath)
filePath
- current file's pathString
program directory pathpublic static String getProjectDir(Path filePath)
filePath
- file pathString
project directory path or null if not in a projectpublic static Path getCurrentModulePath(Path filePath)
If it is a non-project file; returns immediate parent.
filePath
- file pathpublic static boolean isBallerinaProject(String root, String fileUri)
root
- root pathfileUri
- file UriBoolean
true if project dir, else falsepublic static String getPackageNameForGivenFile(String sourceRoot, String filePath)
sourceRoot
- source rootfilePath
- full path of the fileString
package namepublic static Path createTempFile(String tempFileId)
tempFileId
- temp file idpublic static Optional<String> getUntitledFileId(String filePath)
filePath
- file pathCopyright © 2019 WSO2. All rights reserved.