Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Initializing = 'Initializing',
Initialized = 'Initialized',
}
interface Workspace {
lastAccess: number;
status: WorkspaceStatus;
initPromise?: Cancelable;
}
export interface InitializeOptions {
clientCapabilities?: ClientCapabilities;
initialOptions?: object;
}
export const WorkspaceUnloadedError = new ResponseError(RequestCancelled, 'Workspace unloaded');
export class RequestExpander implements ILanguageServerHandler {
public lastAccess: number = 0;
private proxy: LanguageServerProxy;
// a map for workspacePath -> Workspace
private workspaces: Map = new Map();
private readonly workspaceRoot: string;
private exited = false;
constructor(
proxy: LanguageServerProxy,
readonly builtinWorkspace: boolean,
readonly maxWorkspace: number,
readonly serverOptions: ServerOptions,
readonly initialOptions: InitializeOptions,
readonly log: Logger
public connected(): Promise {
if (this.closed) {
return Promise.reject(new ResponseError(RequestCancelled, 'Server closed'));
} else if (this.error) {
return Promise.reject(new ResponseError(InternalError, 'Server error', this.error));
} else if (this.clientConnection) {
return Promise.resolve(this.clientConnection);
} else {
return new Promise((resolve, reject) => {
this.eventEmitter.on('err', error =>
reject(new ResponseError(InternalError, 'Server error', error))
);
this.eventEmitter.on('exit', () =>
reject(new ResponseError(RequestCancelled, 'Server closed'))
);
this.eventEmitter.on('connect', () => resolve(this.clientConnection!));
});
}
}
public connected(): Promise {
if (this.closed) {
return Promise.reject(new ResponseError(RequestCancelled, 'Server closed'));
} else if (this.error) {
return Promise.reject(new ResponseError(InternalError, 'Server error', this.error));
} else if (this.clientConnection) {
return Promise.resolve(this.clientConnection);
} else {
return new Promise((resolve, reject) => {
this.eventEmitter.on('err', error =>
reject(new ResponseError(InternalError, 'Server error', error))
);
this.eventEmitter.on('exit', () =>
reject(new ResponseError(RequestCancelled, 'Server closed'))
);
this.eventEmitter.on('connect', () => resolve(this.clientConnection!));
});
}
}
this.eventEmitter.on('exit', () =>
reject(new ResponseError(RequestCancelled, 'Server closed'))
);
signal?: AbortSignal
): Promise {
try {
const response = await kfetch({
pathname: `${this.baseUri}/${method}`,
method: 'POST',
body: JSON.stringify(params),
signal,
});
return response as ResponseMessage;
} catch (e) {
let error = e;
if (error.body && error.body.error) {
error = error.body.error;
}
throw new ResponseError(error.code, error.message, error.data);
}
}
}
this.eventEmitter.on('err', error =>
reject(new ResponseError(InternalError, 'Server error', error))
);