diff --git a/extension/server/src/providers/completionItem.ts b/extension/server/src/providers/completionItem.ts index 262e6be..528a426 100644 --- a/extension/server/src/providers/completionItem.ts +++ b/extension/server/src/providers/completionItem.ts @@ -30,6 +30,7 @@ export default async function completionItemProvider(handler: CompletionParams): // If they're typing inside of a procedure, let's get the stuff from there too const currentProcedure = doc.procedures.find((proc, index) => + proc.range.start && proc.range.end && lineNumber >= proc.range.start && (lineNumber <= proc.range.end+1 || index === doc.procedures.length-1) && currentPath === proc.position.path diff --git a/extension/server/src/providers/definition.ts b/extension/server/src/providers/definition.ts index 3d816da..f9410e8 100644 --- a/extension/server/src/providers/definition.ts +++ b/extension/server/src/providers/definition.ts @@ -31,9 +31,9 @@ export default async function definitionProvider(handler: DefinitionParams): Pro return Location.create( def.position.path, Range.create( - def.position.line, + def.position.range.line, 0, - def.position.line, + def.position.range.line, 0 ) ); @@ -49,9 +49,9 @@ export default async function definitionProvider(handler: DefinitionParams): Pro return Location.create( def.position.path, Range.create( - def.position.line, + def.position.range.line, 0, - def.position.line, + def.position.range.line, 0 ) ); diff --git a/extension/server/src/providers/documentSymbols.ts b/extension/server/src/providers/documentSymbols.ts index b3f146a..464ee17 100644 --- a/extension/server/src/providers/documentSymbols.ts +++ b/extension/server/src/providers/documentSymbols.ts @@ -1,6 +1,7 @@ import { DocumentSymbol, DocumentSymbolParams, Range, SymbolKind } from 'vscode-languageserver'; import { documents, parser, prettyKeywords } from '.'; import Cache from '../../../../language/models/cache'; +import { Position } from '../../../../language/models/DataPoints'; export default async function documentSymbolProvider(handler: DocumentSymbolParams): Promise { const currentPath = handler.textDocument.uri; @@ -18,14 +19,14 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara const currentScopeDefs: DocumentSymbol[] = []; scope.procedures - .filter(proc => proc.position && proc.position.path === currentPath) + .filter(proc => proc.position && proc.position.path === currentPath && proc.range.start && proc.range.end) .forEach(proc => { const procDef = DocumentSymbol.create( proc.name, 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), + Range.create(proc.range.start!, 0, proc.range.end!, 0), + Range.create(proc.range.start!, 0, proc.range.start!, 0), ); if (proc.scope) { @@ -35,8 +36,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara subitem.name, 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) + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0), + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0) )); procDef.children.push(...getScopeVars(proc.scope)); @@ -46,14 +47,14 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara }); currentScopeDefs.push( - ...scope.subroutines.filter(sub => sub.position && sub.position.path === currentPath) + ...scope.subroutines.filter(sub => sub.position && sub.position.path === currentPath && sub.range.start && sub.range.end) .filter(def => def.range.start) .map(def => DocumentSymbol.create( def.name, 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), + Range.create(def.range.start!, 0, def.range.end!, 0), + Range.create(def.range.start!, 0, def.range.start!, 0), )), ...scope.variables @@ -62,8 +63,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara def.name, 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) + Range.create(def.position.range.line, 0, def.position.range.line, 0), + Range.create(def.position.range.line, 0, def.position.range.line, 0) )) ); @@ -74,8 +75,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara def.name, 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) + Range.create(def.position.range.line, 0, def.position.range.line, 0), + Range.create(def.position.range.line, 0, def.position.range.line, 0) ); if (def.subItems.length > 0) { @@ -85,8 +86,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara subitem.name, 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) + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0), + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0) )); } @@ -100,8 +101,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara file.name, 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) + Range.create(file.position.range.line, 0, file.position.range.line, 0), + Range.create(file.position.range.line, 0, file.position.range.line, 0) ); fileDef.children = []; @@ -113,8 +114,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara recordFormat.name, 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) + Range.create(recordFormat.position.range.line, 0, recordFormat.position.range.line, 0), + Range.create(recordFormat.position.range.line, 0, recordFormat.position.range.line, 0) ); recordFormatDef.children = recordFormat.subItems @@ -123,8 +124,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara subitem.name, 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) + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0), + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0) )); if (fileDef.children) { @@ -136,14 +137,14 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara }); scope.structs - .filter(struct => struct.position && struct.position.path === currentPath) + .filter(struct => struct.position && struct.position.path === currentPath && struct.range.start && struct.range.end) .forEach(struct => { const structDef = DocumentSymbol.create( struct.name, 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), + Range.create(struct.range.start!, 0, struct.range.end!, 0), + Range.create(struct.range.start!, 0, struct.range.start!, 0), ); structDef.children = struct.subItems @@ -152,8 +153,8 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara subitem.name, 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) + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0), + Range.create(subitem.position.range.line, 0, subitem.position.range.line, 0) )); currentScopeDefs.push(structDef); diff --git a/extension/server/src/providers/hover.ts b/extension/server/src/providers/hover.ts index 70c099b..ae04c5f 100644 --- a/extension/server/src/providers/hover.ts +++ b/extension/server/src/providers/hover.ts @@ -59,7 +59,7 @@ export default async function hoverProvider(params: HoverParams): Promise currentLine >= proc.range.start && currentLine <= proc.range.end); + const currentProcedure = doc.procedures.find(proc => proc.range.start && proc.range.end && currentLine >= proc.range.start && currentLine <= proc.range.end); let theVariable; if (currentProcedure && currentProcedure.scope) { @@ -88,7 +88,7 @@ export default async function hoverProvider(params: HoverParams): Promise - range.start.line >= document.positionAt(error.offset.position!).line && + range.start.line >= document.positionAt(error.offset.start!).line && range.end.line <= document.positionAt(error.offset.end!).line ); diff --git a/extension/server/src/providers/linter/index.ts b/extension/server/src/providers/linter/index.ts index 8d543b9..f242523 100644 --- a/extension/server/src/providers/linter/index.ts +++ b/extension/server/src/providers/linter/index.ts @@ -86,7 +86,7 @@ export function calculateOffset(document: TextDocument, error: IssueRange) { const offset = error.offset; return Range.create( - document.positionAt(error.offset.position), + document.positionAt(error.offset.start), document.positionAt(error.offset.end) ); }; @@ -435,17 +435,17 @@ export function getActions(document: TextDocument, errors: IssueRange[]) { export function getSubroutineActions(document: TextDocument, docs: Cache, range: Range): CodeAction|undefined { if (range.start.line === range.end.line) { - const currentGlobalSubroutine = docs.subroutines.find(sub => sub.position.line === range.start.line); + const currentGlobalSubroutine = docs.subroutines.find(sub => sub.position.range.line === range.start.line && sub.range.start && sub.range.end); if (currentGlobalSubroutine) { const subroutineRange = Range.create( - Position.create(currentGlobalSubroutine.range.start, 0), - Position.create(currentGlobalSubroutine.range.end, 1000) + Position.create(currentGlobalSubroutine.range.start!, 0), + Position.create(currentGlobalSubroutine.range.end!, 1000) ); const bodyRange = Range.create( - Position.create(currentGlobalSubroutine.range.start + 1, 0), - Position.create(currentGlobalSubroutine.range.end - 1, 0) + Position.create(currentGlobalSubroutine.range.start! + 1, 0), + Position.create(currentGlobalSubroutine.range.end! - 1, 0) ); // First, let's create the extract data @@ -464,13 +464,13 @@ export function getSubroutineActions(document: TextDocument, docs: Cache, range: // Then update the references that invokes this subroutine const referenceUpdates: TextEdit[] = currentGlobalSubroutine.references.map(ref => { - const lineNumber = document.positionAt(ref.offset.position).line; + const lineNumber = document.positionAt(ref.offset.start).line; // If this reference is outside of the subroutine - if (lineNumber < currentGlobalSubroutine.range.start || lineNumber > currentGlobalSubroutine.range.end) { + if (lineNumber < currentGlobalSubroutine.range.start! || lineNumber > currentGlobalSubroutine.range.end!) { return TextEdit.replace( Range.create( // - 5 `EXSR ` - document.positionAt(ref.offset.position - 5), + document.positionAt(ref.offset.start - 5), document.positionAt(ref.offset.end) ), currentGlobalSubroutine.name + `(${extracted.references.map(r => r.dec.name).join(`:`)})` @@ -538,7 +538,7 @@ function caseInsensitiveReplaceAll(text: string, search: string, replace: string function createExtract(document: TextDocument, userRange: Range, docs: Cache) { const range = Range.create(userRange.start.line, 0, userRange.end.line, 1000); - const references = docs.referencesInRange(document.uri, {position: document.offsetAt(range.start), end: document.offsetAt(range.end)}); + const references = docs.referencesInRange(document.uri, {start: document.offsetAt(range.start), end: document.offsetAt(range.end)}); const validRefs = references.filter(ref => [`struct`, `subitem`, `variable`].includes(ref.dec.type)); const nameDiffSize = 1; // Always once since we only add 'p' at the start @@ -551,7 +551,7 @@ function createExtract(document: TextDocument, userRange: Range, docs: Cache) { for (let i = validRefs.length - 1; i >= 0; i--) { for (let y = validRefs[i].refs.length - 1; y >= 0; y--) { validRefs[i].refs[y] = { - position: validRefs[i].refs[y].position - rangeStartOffset, + start: validRefs[i].refs[y].start - rangeStartOffset, end: validRefs[i].refs[y].end - rangeStartOffset }; } @@ -562,15 +562,15 @@ function createExtract(document: TextDocument, userRange: Range, docs: Cache) { for (let y = validRefs[i].refs.length - 1; y >= 0; y--) { const ref = validRefs[i].refs[y]; - newBody = newBody.slice(0, ref.position) + newParamNames[i] + newBody.slice(ref.end); + newBody = newBody.slice(0, ref.start) + newParamNames[i] + newBody.slice(ref.end); ref.end += nameDiffSize; // Then we need to update the offset of the next references for (let z = i - 1; z >= 0; z--) { for (let x = validRefs[z].refs.length - 1; x >= 0; x--) { - if (validRefs[z].refs[x].position > ref.end) { + if (validRefs[z].refs[x].start > ref.end) { validRefs[z].refs[x] = { - position: validRefs[z].refs[x].position + nameDiffSize, + start: validRefs[z].refs[x].start + nameDiffSize, end: validRefs[z].refs[x].end + nameDiffSize }; } diff --git a/extension/server/src/providers/project/workspaceSymbol.ts b/extension/server/src/providers/project/workspaceSymbol.ts index 2ddd2e4..59d8e65 100644 --- a/extension/server/src/providers/project/workspaceSymbol.ts +++ b/extension/server/src/providers/project/workspaceSymbol.ts @@ -55,9 +55,9 @@ export default function workspaceSymbolProvider(params: WorkspaceSymbolParams): SymbolKind.Function, uri, Range.create( - proc.position.line, + proc.position.range.line, 0, - proc.position.line, + proc.position.range.line, 0 ) ) diff --git a/extension/server/src/providers/rename.ts b/extension/server/src/providers/rename.ts index 4cc468e..42587cc 100644 --- a/extension/server/src/providers/rename.ts +++ b/extension/server/src/providers/rename.ts @@ -23,11 +23,11 @@ export async function renamePrepareProvider(params: PrepareRenameParams): Promis return; } - const currentSelectedRef = def?.references.find(r => document.positionAt(r.offset.position).line === currentPos.line); + const currentSelectedRef = def?.references.find(r => document.positionAt(r.offset.start).line === currentPos.line); if (currentSelectedRef) { return Range.create( - document.positionAt(currentSelectedRef.offset.position), + document.positionAt(currentSelectedRef.offset.start), document.positionAt(currentSelectedRef.offset.end) ) } @@ -60,7 +60,7 @@ export async function renameRequestProvider(params: RenameParams): Promise ref.uri === uri).map(ref => ({ newText: params.newName, range: Range.create( - document.positionAt(ref.offset.position), + document.positionAt(ref.offset.start), document.positionAt(ref.offset.end) ) }));