@abaplint/core
Version:
abaplint - Core API
149 lines • 6.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LanguageServer = void 0;
const LServer = require("vscode-languageserver-types");
const symbols_1 = require("./symbols");
const hover_1 = require("./hover");
const diagnostics_1 = require("./diagnostics");
const help_1 = require("./help");
const pretty_printer_1 = require("../pretty_printer/pretty_printer");
const definition_1 = require("./definition");
const rename_1 = require("./rename");
const highlight_1 = require("./highlight");
const _lsp_utils_1 = require("./_lsp_utils");
const code_actions_1 = require("./code_actions");
const references_1 = require("./references");
const implementation_1 = require("./implementation");
const semantic_1 = require("./semantic");
const statement_flow_1 = require("../abap/flow/statement_flow");
const code_lens_1 = require("./code_lens");
const inlay_hints_1 = require("./inlay_hints");
// note Ranges are zero based in LSP,
// https://github.com/microsoft/language-server-protocol/blob/main/versions/protocol-2-x.md#range
// but 1 based in abaplint
// the types in this file are not completely correct
// see https://github.com/microsoft/vscode-languageserver-node/issues/354
class LanguageServer {
constructor(reg) {
this.reg = reg;
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_documentSymbol
documentSymbol(params) {
return new symbols_1.Symbols(this.reg).find(params.textDocument.uri);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_hover
hover(params) {
const hover = new hover_1.Hover(this.reg).find(params);
if (hover) {
return { contents: hover };
}
return undefined;
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_definition
gotoDefinition(params) {
return new definition_1.Definition(this.reg).find(params.textDocument, params.position);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_formatting
documentFormatting(params) {
const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, params.textDocument.uri);
if (file === undefined) {
return [];
}
const text = new pretty_printer_1.PrettyPrinter(file, this.reg.getConfig()).run();
const rows = file.getRawRows();
if (text === file.getRaw()) {
return [];
}
else {
return [{
range: LServer.Range.create(0, 0, rows.length, rows[rows.length - 1].length + 1),
newText: text,
}];
}
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_publishDiagnostics
diagnostics(textDocument) {
return new diagnostics_1.Diagnostics(this.reg).find(textDocument);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_prepareRename
prepareRename(params) {
return new rename_1.Rename(this.reg).prepareRename(params);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_rename
rename(params) {
return new rename_1.Rename(this.reg).rename(params);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_codeAction
codeActions(params) {
return new code_actions_1.CodeActions(this.reg).find(params);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_documentHighlight
documentHighlight(_params) {
// todo, implement
return [];
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_implementation
implementation(params) {
return new implementation_1.Implementation(this.reg).find(params.textDocument, params.position);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_references
references(params) {
return new references_1.References(this.reg).references(params);
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#semanticTokensLegend
static semanticTokensLegend() {
return semantic_1.SemanticHighlighting.semanticTokensLegend();
}
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#semanticTokensRangeParams
semanticTokensRange(range) {
return new semantic_1.SemanticHighlighting(this.reg).semanticTokensRange(range);
}
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeLens
codeLens(textDocument, settings) {
return new code_lens_1.CodeLens(this.reg).list(textDocument, settings);
}
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
inlayHints(textDocument, settings) {
return new inlay_hints_1.InlayHints(this.reg).list(textDocument, settings);
}
////////////////////////////////////////
// ______ _
// | ____| | |
// | |__ __ _| |_ _ __ __ ___
// | __| \ \/ / __| '__/ _` / __|
// | |____ > <| |_| | | (_| \__ \
// |______/_/\_\\__|_| \__,_|___/
// extras, abaplint specific
////////////////////////////////////////
help(textDocument, position) {
return help_1.Help.find(this.reg, textDocument, position);
}
listDefinitionPositions(textDocument) {
return new highlight_1.Highlight(this.reg).listDefinitionPositions(textDocument);
}
listReadPositions(textDocument) {
return new highlight_1.Highlight(this.reg).listReadPositions(textDocument);
}
listWritePositions(textDocument) {
return new highlight_1.Highlight(this.reg).listWritePositions(textDocument);
}
dumpStatementFlows(textDocument) {
const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, textDocument.uri);
if (file === undefined) {
return "file not found";
}
const obj = this.reg.findObjectForFile(file);
if (obj === undefined) {
return "obj not found";
}
const stru = file.getStructure();
if (stru === undefined) {
return "empty structure";
}
const graphs = new statement_flow_1.StatementFlow().build(stru, obj);
const wiz = graphs.map(g => g.toDigraph());
return JSON.stringify(wiz);
}
}
exports.LanguageServer = LanguageServer;
//# sourceMappingURL=language_server.js.map