pss-langserver
Version:
A Language server for the Portable Stimulus Standard
94 lines (93 loc) • 3.69 kB
JavaScript
;
/*
* Copyright (C) 2025 Darshan(@thisisthedarshan)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildAutocompletionBuiltinsBlock = buildAutocompletionBuiltinsBlock;
exports.buildAutocompletionBlock = buildAutocompletionBlock;
exports.buildAutocompletions = buildAutocompletions;
const node_1 = require("vscode-languageserver/node");
const builtinFunctions_1 = require("../definitions/builtinFunctions");
const keywords_1 = require("../definitions/keywords");
const autoCompletionHelpers_1 = require("./autoCompletionHelpers");
const helpers_1 = require("../parser/helpers");
function buildAutocompletionBuiltinsBlock() {
let items = [];
/* Build the autocompletions with built-in code */
keywords_1.keywords.list.forEach((key, idx) => {
if (!(key in builtinFunctions_1.builtInSignatures)) {
items.push({
label: key,
detail: keywords_1.keywords.descriptions[idx],
kind: node_1.CompletionItemKind.Keyword
});
}
});
/* Add function signatures */
Object.entries(builtinFunctions_1.builtInSignatures).forEach(([name, func]) => {
items.push({
label: name,
kind: node_1.CompletionItemKind.Function,
detail: func.signature,
documentation: {
kind: 'markdown',
value: `${func.documentation}\n\n**Parameters:**\n${func.parameters.map(p => `- \`${p.label}\`: ${p.documentation}`).join('\n')}`
}
});
});
return items;
}
function buildAutocompletionBlock(ast) {
let items = [];
ast.map(astItem => {
Object.entries(astItem).map(([name, meta]) => {
items.push({
label: name,
kind: (0, autoCompletionHelpers_1.getCompletionKind)(meta.objectType),
documentation: (meta.documentation !== undefined) ? (meta.documentation.length > 0) ? {
kind: 'markdown',
value: meta.documentation
} : undefined : undefined
});
});
});
return items;
}
function buildAutocompletions(ast) {
let items = [];
ast.forEach(item => {
/** Get data from each node */
let completionItem = {
label: item.name,
kind: (0, autoCompletionHelpers_1.getCompletionKind)(item.type),
documentation: (typeof item.comments === 'string') ? item.comments : {
kind: 'markdown',
value: (0, helpers_1.buildMarkdownComment)(item.comments)
},
data: item.name
};
const existingItem = items.find(i => i.label === item.name);
if (!existingItem) {
// No duplicate, add to items
items.push(completionItem);
}
if (item.children.length > 0) {
const childItems = buildAutocompletions(item.children);
items = [...items, ...childItems];
}
});
return items;
}