From f4dc3aea3905ffe71b52678d3ab756875d39f926 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Thu, 5 Dec 2024 16:14:58 -0500 Subject: [PATCH] Fix up language server to use new interface for keywords Signed-off-by: worksofliam --- .../server/src/providers/completionItem.ts | 26 +++++++++---------- .../server/src/providers/documentSymbols.ts | 24 ++++++++--------- extension/server/src/providers/hover.ts | 19 +++++++++----- extension/server/src/providers/index.ts | 16 ++++++++++++ .../src/providers/project/exportInterfaces.ts | 20 +++++--------- 5 files changed, 61 insertions(+), 44 deletions(-) diff --git a/extension/server/src/providers/completionItem.ts b/extension/server/src/providers/completionItem.ts index 0cb41bcc..262e6bea 100644 --- a/extension/server/src/providers/completionItem.ts +++ b/extension/server/src/providers/completionItem.ts @@ -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'; @@ -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; })); @@ -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); } @@ -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); } @@ -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); } @@ -145,7 +145,7 @@ 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); @@ -153,7 +153,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); @@ -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); }); @@ -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); @@ -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); }); @@ -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); @@ -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); }); @@ -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); } diff --git a/extension/server/src/providers/documentSymbols.ts b/extension/server/src/providers/documentSymbols.ts index ddb3e94d..b3f146aa 100644 --- a/extension/server/src/providers/documentSymbols.ts +++ b/extension/server/src/providers/documentSymbols.ts @@ -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 { @@ -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), @@ -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) @@ -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), @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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), @@ -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) diff --git a/extension/server/src/providers/hover.ts b/extension/server/src/providers/hover.ts index 9c3949ce..547fd85f 100644 --- a/extension/server/src/providers/hover.ts +++ b/extension/server/src/providers/hover.ts @@ -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 { const currentPath = params.textDocument.uri; @@ -18,8 +19,14 @@ export default async function hoverProvider(params: HoverParams): Promise 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`); @@ -33,10 +40,10 @@ export default async function hoverProvider(params: HoverParams): Promise 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) @@ -76,7 +83,7 @@ export default async function hoverProvider(params: HoverParams): Promise = new TextDocuments(TextDocument); @@ -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(` `); } \ No newline at end of file diff --git a/extension/server/src/providers/project/exportInterfaces.ts b/extension/server/src/providers/project/exportInterfaces.ts index cfb42e78..2c35556f 100644 --- a/extension/server/src/providers/project/exportInterfaces.ts +++ b/extension/server/src/providers/project/exportInterfaces.ts @@ -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[] = []; @@ -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;` ]; @@ -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;` ];