import * as vscode from "vscode" ; import { Range } from "vscode-languageserver-types" ; import * as commands from "./commands" ; export enum CompileWorkspaceStatus { FAILED = 0 , SUCCEED = 1 , WITHERROR = 2 , CANCELLED = 3 } export interface IMainClassOption { readonly mainClass : string ; readonly projectName ? : string ; readonly filePath ? : string ; } export interface IMainMethod extends IMainClassOption { range : vscode . Range ; } export const CONFIGERROR_INVALID_CLASS_NAME = 1 ; export const CONFIGERROR_MAIN_CLASS_NOT_EXIST = 2 ; export const CONFIGERROR_MAIN_CLASS_NOT_UNIQUE = 3 ; export const CONFIGERROR_INVALID_JAVA_PROJECT = 4 ; export interface IValidationResult { readonly isValid : boolean ; readonly message ? : string ; readonly kind ? : number ; } export interface ILaunchValidationResponse { readonly mainClass : IValidationResult ; readonly projectName : IValidationResult ; readonly proposals ? : IMainClassOption [ ] ; } export async function resolveMainMethod ( uri , token ? ) { if ( token ) { return < IMainMethod [ ] > await commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_MAINMETHOD , uri . toString ( ) , token ) ; } return < IMainMethod [ ] > await commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_MAINMETHOD , uri . toString ( ) ) ; } export function startDebugSession ( ) { return commands . executeJavaLanguageServerCommand ( commands . JAVA_START_DEBUGSESSION ) ; } export function resolveClasspath ( mainClass , projectName , scope ? ) { return commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_CLASSPATH , mainClass , projectName , scope ) ; } export function resolveMainClass ( workspaceUri ? ) { if ( workspaceUri ) { return < Promise < IMainClassOption [ ] > > commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_MAINCLASS , workspaceUri . toString ( ) ) ; } return < Promise < IMainClassOption [ ] > > commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_MAINCLASS ) ; } export function validateLaunchConfig ( mainClass , projectName , containsExternalClasspaths , workspaceUri ? ) { return < Promise < ILaunchValidationResponse > > commands . executeJavaLanguageServerCommand ( commands . JAVA_VALIDATE_LAUNCHCONFIG , workspaceUri ? workspaceUri . toString ( ) : undefined , mainClass , projectName , containsExternalClasspaths ) ; } export function inferLaunchCommandLength ( config ) { return < Promise < number > > commands . executeJavaLanguageServerCommand ( commands . JAVA_INFER_LAUNCH_COMMAND_LENGTH , JSON . stringify ( config ) ) ; } export function checkProjectSettings ( className , projectName , inheritedOptions , expectedOptions ) { return < Promise < boolean > > commands . executeJavaLanguageServerCommand ( commands . JAVA_CHECK_PROJECT_SETTINGS , JSON . stringify ( { className , projectName , inheritedOptions , expectedOptions , } ) ) ; } const COMPILER_PB_ENABLE_PREVIEW_FEATURES = "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures" ; export async function detectPreviewFlag ( className , projectName ) { const expectedOptions = { [ COMPILER_PB_ENABLE_PREVIEW_FEATURES ] : "enabled" , } ; return checkProjectSettings ( className , projectName , true , expectedOptions ) ; } export function resolveElementAtSelection ( uri , line , character ) { return < Promise < any > > commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_ELEMENT_AT_SELECTION , uri , line , character ) ; } export function resolveBuildFiles ( ) { return < Promise < string [ ] > > commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_BUILD_FILES ) ; } export async function isOnClasspath ( uri ) { try { return < boolean > await commands . executeJavaExtensionCommand ( commands . JAVA_IS_ON_CLASSPATH , uri ) ; } catch ( error ) { return true ; } } export function resolveJavaExecutable ( mainClass , projectName ) { return commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_JAVAEXECUTABLE , mainClass , projectName ) ; } export function fetchPlatformSettings ( ) { return commands . executeJavaLanguageServerCommand ( commands . JAVA_FETCH_PLATFORM_SETTINGS ) ; } export async function resolveClassFilters ( patterns ) { return < string [ ] > await commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_CLASSFILTERS , ... patterns ) ; } export async function resolveSourceUri ( line ) { return < string > await commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_SOURCE_URI , line ) ; } export async function resolveInlineVariables ( inlineParams ) { return < InlineVariable [ ] > await commands . executeJavaLanguageServerCommand ( commands . JAVA_RESOLVE_INLINE_VARIABLES , JSON . stringify ( inlineParams ) ) ; } export interface InlineParams { uri : string ; viewPort ? : Range ; stoppedLocation : Range ; } export enum InlineKind { VariableLookup = 0 , Evaluation = 1 } export interface InlineVariable { range : Range ; name : string ; kind : InlineKind ; expression : string ; declaringClass : string ; }