Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async handleRequest(request: LspRequest): Promise {
const file = request.resolvedFilePath;
if (file) {
// #todo add test for this
const lang = await detectLanguage(file.replace('file://', ''));
if (await this.repoConfigController.isLanguageDisabled(request.documentUri!, lang)) {
throw new ResponseError(LanguageDisabled, `language disabled for the file`);
}
return await this.dispatchRequest(lang, request);
} else {
throw new ResponseError(UnknownErrorCode, `can't detect language without a file`);
}
}
public async indexSymbols(id: types.TextDocumentIdentifier): Promise> {
const request = merlin.Query.outline();
const response = await this.session.merlin.query(request, id);
if (response.class !== "return") return new rpc.ResponseError(-1, "indexSymbols: failed", undefined);
for (const item of merlin.Outline.intoCode(response.value, id)) {
const prefix = item.containerName ? `${item.containerName}.` : "";
item.name = `${prefix}${item.name}`;
item.containerName = this.session.environment.relativize(id);
this.symbols.insert(item);
}
};
private async findOrCreateHandler(
languageServer: LanguageServerData,
request: LspRequest
): Promise {
let handlers: LanguageServerHandlerMap;
if (languageServer.languageServerHandlers) {
handlers = languageServer.languageServerHandlers as LanguageServerHandlerMap;
} else {
handlers = languageServer.languageServerHandlers = {};
}
if (!request.workspacePath) {
throw new ResponseError(UnknownErrorCode, `no workspace in request?`);
}
const realPath = fs.realpathSync(request.workspacePath);
let handler = handlers[realPath];
if (handler) {
return handler;
} else {
const maxWorkspace = languageServer.maxWorkspace;
const handlerArray = Object.entries(handlers);
if (handlerArray.length < maxWorkspace) {
handler = languageServer.launcher.launch(
languageServer.builtinWorkspaceFolders,
maxWorkspace
);
handlers[realPath] = handler;
return handler;
} else {
protected serializeError(e: any): any {
if (ApplicationError.is(e)) {
return new ResponseError(e.code, '',
Object.assign({ kind: 'application' }, e.toJson())
);
}
return e;
}
protected deserializeError(capturedError: Error, e: any): any {
function _throwError(message) {
throw new ResponseError(ErrorCodes.InvalidParams, message);
}