Skip to content

Commit

Permalink
Fix up language server to use new interface for keywords
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 5, 2024
1 parent 207ef62 commit f4dc3ae
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 44 deletions.
26 changes: 13 additions & 13 deletions extension/server/src/providers/completionItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');
import { CompletionItem, CompletionItemKind, CompletionParams, InsertTextFormat, Position, Range } from 'vscode-languageserver';
import { documents, getWordRangeAtPosition, parser } from '.';
import { documents, getWordRangeAtPosition, parser, prettyKeywords } from '.';
import Cache from '../../../../language/models/cache';
import Declaration from '../../../../language/models/declaration';
import * as ileExports from './apis';
Expand Down Expand Up @@ -78,7 +78,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(subItem.name);
item.kind = CompletionItemKind.Property;
item.insertText = subItem.name;
item.detail = subItem.keywords.join(` `);
item.detail = prettyKeywords(subItem.keyword);
item.documentation = subItem.description + `${possibleStruct ? ` (${possibleStruct.name})` : ``}`;
return item;
}));
Expand Down Expand Up @@ -109,7 +109,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${subItem.name}`);
item.kind = CompletionItemKind.TypeParameter;
item.insertText = subItem.name;
item.detail = [`parameter`, ...subItem.keywords].join(` `);
item.detail = [`parameter`, prettyKeywords(subItem.keyword)].join(` `);
item.documentation = subItem.description;
items.push(item);
}
Expand All @@ -119,7 +119,7 @@ export default async function completionItemProvider(handler: CompletionParams):
item.kind = CompletionItemKind.Function;
item.insertTextFormat = InsertTextFormat.Snippet;
item.insertText = `${procedure.name}(${procedure.subItems.map((parm, index) => `\${${index + 1}:${parm.name}}`).join(`:`)})`;
item.detail = procedure.keywords.join(` `);
item.detail = prettyKeywords(procedure.keyword);
item.documentation = procedure.description;
items.push(item);
}
Expand All @@ -136,7 +136,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${variable.name}`);
item.kind = CompletionItemKind.Variable;
item.insertText = `${variable.name}`;
item.detail = variable.keywords.join(` `);
item.detail = prettyKeywords(variable.keyword);
item.documentation = variable.description;
items.push(item);
}
Expand All @@ -145,15 +145,15 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${file.name}`);
item.kind = CompletionItemKind.File;
item.insertText = `${file.name}`;
item.detail = file.keywords.join(` `);
item.detail = prettyKeywords(file.keyword);
item.documentation = file.description;
items.push(item);

for (const struct of file.subItems) {
const item = CompletionItem.create(`${struct.name}`);
item.kind = CompletionItemKind.Struct;
item.insertText = `${struct.name}`;
item.detail = struct.keywords.join(` `);
item.detail = prettyKeywords(struct.keyword);
item.documentation = struct.description;
items.push(item);

Expand All @@ -162,7 +162,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${subItem.name}`);
item.kind = CompletionItemKind.Property;
item.insertText = `${subItem.name}`;
item.detail = subItem.keywords.join(` `);
item.detail = prettyKeywords(subItem.keyword);
item.documentation = subItem.description + ` (${struct.name})`;
items.push(item);
});
Expand All @@ -174,7 +174,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${struct.name}`);
item.kind = CompletionItemKind.Struct;
item.insertText = `${struct.name}`;
item.detail = struct.keywords.join(` `);
item.detail = prettyKeywords(struct.keyword);
item.documentation = struct.description;
items.push(item);

Expand All @@ -183,7 +183,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${subItem.name}`);
item.kind = CompletionItemKind.Property;
item.insertText = `${subItem.name}`;
item.detail = subItem.keywords.join(` `);
item.detail = prettyKeywords(subItem.keyword);
item.documentation = subItem.description + ` (${struct.name})`;
items.push(item);
});
Expand All @@ -194,7 +194,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${constant.name}`);
item.kind = CompletionItemKind.Constant;
item.insertText = `${constant.name}`;
item.detail = constant.keywords.join(` `);
item.detail = prettyKeywords(constant.keyword);
item.documentation = constant.description;
items.push(item);

Expand All @@ -203,7 +203,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${subItem.name}`);
item.kind = CompletionItemKind.Property;
item.insertText = `${subItem.name}`;
item.detail = subItem.keywords.join(` `);
item.detail = prettyKeywords(subItem.keyword);
item.documentation = subItem.description + ` (${constant.name})`;
items.push(item);
});
Expand All @@ -226,7 +226,7 @@ export default async function completionItemProvider(handler: CompletionParams):
const item = CompletionItem.create(`${subItem.name}`);
item.kind = CompletionItemKind.TypeParameter;
item.insertText = subItem.name;
item.detail = [`parameter`, ...subItem.keywords].join(` `);
item.detail = [`parameter`, prettyKeywords(subItem.keyword)].join(` `);
item.documentation = subItem.description;
items.push(item);
}
Expand Down
24 changes: 12 additions & 12 deletions extension/server/src/providers/documentSymbols.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentSymbol, DocumentSymbolParams, Range, SymbolKind } from 'vscode-languageserver';
import { documents, parser } from '.';
import { documents, parser, prettyKeywords } from '.';
import Cache from '../../../../language/models/cache';

export default async function documentSymbolProvider(handler: DocumentSymbolParams): Promise<DocumentSymbol[]> {
Expand All @@ -22,7 +22,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.forEach(proc => {
const procDef = DocumentSymbol.create(
proc.name,
proc.keywords.join(` `).trim(),
prettyKeywords(proc.keyword),
SymbolKind.Function,
Range.create(proc.range.start, 0, proc.range.end, 0),
Range.create(proc.range.start, 0, proc.range.start, 0),
Expand All @@ -33,7 +33,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(subitem => subitem.position && subitem.position.path === currentPath)
.map(subitem => DocumentSymbol.create(
subitem.name,
subitem.keywords.join(` `).trim(),
prettyKeywords(subitem.keyword),
SymbolKind.Property,
Range.create(subitem.position.line, 0, subitem.position.line, 0),
Range.create(subitem.position.line, 0, subitem.position.line, 0)
Expand All @@ -50,7 +50,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(def => def.range.start)
.map(def => DocumentSymbol.create(
def.name,
def.keywords.join(` `).trim(),
prettyKeywords(def.keyword),
SymbolKind.Function,
Range.create(def.range.start, 0, def.range.end, 0),
Range.create(def.range.start, 0, def.range.start, 0),
Expand All @@ -60,7 +60,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(variable => variable.position && variable.position.path === currentPath)
.map(def => DocumentSymbol.create(
def.name,
def.keywords.join(` `).trim(),
prettyKeywords(def.keyword),
SymbolKind.Variable,
Range.create(def.position.line, 0, def.position.line, 0),
Range.create(def.position.line, 0, def.position.line, 0)
Expand All @@ -72,7 +72,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.forEach(def => {
const constantDef = DocumentSymbol.create(
def.name,
def.keywords.join(` `).trim(),
prettyKeywords(def.keyword),
SymbolKind.Constant,
Range.create(def.position.line, 0, def.position.line, 0),
Range.create(def.position.line, 0, def.position.line, 0)
Expand All @@ -83,7 +83,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(subitem => subitem.position && subitem.position.path === currentPath)
.map(subitem => DocumentSymbol.create(
subitem.name,
subitem.keywords.join(` `).trim(),
prettyKeywords(subitem.keyword),
SymbolKind.Property,
Range.create(subitem.position.line, 0, subitem.position.line, 0),
Range.create(subitem.position.line, 0, subitem.position.line, 0)
Expand All @@ -98,7 +98,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.forEach(file => {
const fileDef = DocumentSymbol.create(
file.name,
file.keywords.join(` `).trim(),
prettyKeywords(file.keyword),
SymbolKind.File,
Range.create(file.position.line, 0, file.position.line, 0),
Range.create(file.position.line, 0, file.position.line, 0)
Expand All @@ -111,7 +111,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.forEach(recordFormat => {
const recordFormatDef = DocumentSymbol.create(
recordFormat.name,
recordFormat.keywords.join(` `).trim(),
prettyKeywords(recordFormat.keyword),
SymbolKind.Struct,
Range.create(recordFormat.position.line, 0, recordFormat.position.line, 0),
Range.create(recordFormat.position.line, 0, recordFormat.position.line, 0)
Expand All @@ -121,7 +121,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(subitem => subitem.position && subitem.position.path === currentPath)
.map(subitem => DocumentSymbol.create(
subitem.name,
subitem.keywords.join(` `).trim(),
prettyKeywords(subitem.keyword),
SymbolKind.Property,
Range.create(subitem.position.line, 0, subitem.position.line, 0),
Range.create(subitem.position.line, 0, subitem.position.line, 0)
Expand All @@ -140,7 +140,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.forEach(struct => {
const structDef = DocumentSymbol.create(
struct.name,
struct.keywords.join(` `).trim(),
prettyKeywords(struct.keyword),
SymbolKind.Struct,
Range.create(struct.range.start, 0, struct.range.end, 0),
Range.create(struct.range.start, 0, struct.range.start, 0),
Expand All @@ -150,7 +150,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
.filter(subitem => subitem.position && subitem.position.path === currentPath)
.map(subitem => DocumentSymbol.create(
subitem.name,
subitem.keywords.join(` `).trim(),
prettyKeywords(subitem.keyword),
SymbolKind.Property,
Range.create(subitem.position.line, 0, subitem.position.line, 0),
Range.create(subitem.position.line, 0, subitem.position.line, 0)
Expand Down
19 changes: 13 additions & 6 deletions extension/server/src/providers/hover.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Hover, HoverParams, MarkupKind, Range } from 'vscode-languageserver';
import { documents, getWordRangeAtPosition, parser } from '.';
import { documents, getWordRangeAtPosition, parser, prettyKeywords } from '.';
import Parser from "../../../../language/parser";
import { URI } from 'vscode-uri';
import { Keywords } from '../../../../language/parserTypes';

export default async function hoverProvider(params: HoverParams): Promise<Hover|undefined> {
const currentPath = params.textDocument.uri;
Expand All @@ -18,8 +19,14 @@ export default async function hoverProvider(params: HoverParams): Promise<Hover|

if (procedure) {
let markdown = ``;
let retrunValue = procedure.keywords.filter(keyword => keyword !== `EXTPROC`);
if (retrunValue.length === 0) retrunValue = [`void`];
let returnValue = `void`

let returnKeywords: Keywords = {
...procedure.keyword,
};
delete returnKeywords[`EXTPROC`];

if (Object.keys(returnKeywords).length > 0) returnValue = prettyKeywords(returnKeywords);

const returnTag = procedure.tags.find(tag => tag.tag === `return`);
const deprecatedTag = procedure.tags.find(tag => tag.tag === `deprecated`);
Expand All @@ -33,10 +40,10 @@ export default async function hoverProvider(params: HoverParams): Promise<Hover|
markdown += `\`\`\`vb\n${procedure.name}(`;

if (procedure.subItems.length > 0) {
markdown += `\n ${procedure.subItems.map(parm => `${parm.name}: ${parm.keywords.join(` `).trim()}`).join(`,\n `)}\n`;
markdown += `\n ${procedure.subItems.map(parm => `${parm.name}: ${prettyKeywords(parm.keyword)}`).join(`,\n `)}\n`;
}

markdown += `): ${retrunValue.join(` `)}\n\`\`\` \n`;
markdown += `): ${returnValue}\n\`\`\` \n`;

// Description
if (procedure.description)
Expand Down Expand Up @@ -76,7 +83,7 @@ export default async function hoverProvider(params: HoverParams): Promise<Hover|

if (theVariable) {
// Variable definition found
let markdown = `\`${theVariable.name}\`: \`${theVariable.keywords.join(` `).trim()}\``;
let markdown = `\`${theVariable.name}\`: \`${prettyKeywords(theVariable.keyword)}\``;

if (theVariable.position && currentPath !== theVariable.position.path) {
markdown += `\n\n*@file* \`${theVariable.position.path}:${theVariable.position.line+1}\``;
Expand Down
16 changes: 16 additions & 0 deletions extension/server/src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from 'vscode-languageserver-textdocument';
import Parser from '../../../../language/parser';

type Keywords = {[key: string]: string | boolean};

// Create a simple text document manager.
export const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);

Expand Down Expand Up @@ -40,4 +42,18 @@ export function getWordRangeAtPosition(document: TextDocument, position: Positio
return undefined;
else
return document.getText(Range.create(line, Math.max(0, startChar), line, endChar+1)).replace(/(\r\n|\n|\r)/gm, "");
}

export function prettyKeywords(keywords: Keywords): string {
return Object.keys(keywords).map(key => {
if (keywords[key] ) {
if (typeof keywords[key] === `boolean`) {
return key.toLowerCase();
}

return `${key.toLowerCase()}(${keywords[key]})`;
} else {
return undefined;
}
}).filter(k => k).join(` `);
}
20 changes: 7 additions & 13 deletions extension/server/src/providers/project/exportInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path = require('path');
import { APIInterface } from '../apis';
import { isEnabled } from '.';
import { parser } from '..';
import { parser, prettyKeywords } from '..';

export function getInterfaces(): APIInterface[] {
let interfaces: APIInterface[] = [];
Expand Down Expand Up @@ -30,16 +30,13 @@ export function getInterfaces(): APIInterface[] {

if (entryFunction) {

let keywords = entryFunction.keywords
.map(keyword => keyword.toLowerCase());

// We assume the file name is the name of the object
keywords.push(`extpgm('${objectName}')`);
entryFunction.keyword[`EXTPGM`] = `'${objectName}'`;

const prototype = [
`dcl-pr ${entryFunction.name} ${keywords.join(` `)};`,
`dcl-pr ${entryFunction.name} ${prettyKeywords(entryFunction.keyword)};`,
...entryFunction.subItems.map(subItem =>
` ${subItem.name} ${subItem.keywords.map(keyword => keyword.toLowerCase()).join(` `)};`
` ${subItem.name} ${prettyKeywords(subItem.keyword)};`
),
`end-pr;`
];
Expand All @@ -60,16 +57,13 @@ export function getInterfaces(): APIInterface[] {
// This might mean it is a module. Look for EXPORTs
cache.procedures.forEach(proc => {
if (proc.keyword[`EXPORT`]) {
let keywords = proc.keywords
.map(keyword => keyword.toLowerCase())
.filter(keyword => keyword !== `export`);

keywords.push(`extproc('${proc.name.toUpperCase()}')`);
proc.keyword[`EXTPROC`] = `'${proc.name.toUpperCase()}'`;

const prototype = [
`dcl-pr ${proc.name} ${keywords.join(` `)};`,
`dcl-pr ${proc.name} ${prettyKeywords(proc.keyword)};`,
...proc.subItems.map(subItem =>
` ${subItem.name} ${subItem.keywords.map(keyword => keyword.toLowerCase()).join(` `)};`
` ${subItem.name} ${prettyKeywords(subItem.keyword)};`
),
`end-pr;`
];
Expand Down

0 comments on commit f4dc3ae

Please sign in to comment.