Skip to content

Commit

Permalink
Ensure ranges are attached to definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Barry Allan <[email protected]>
  • Loading branch information
worksofliam committed Aug 19, 2022
1 parent b6a3d73 commit 6e3d5a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/language/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ module.exports = class Linter {

if (rules.CollectReferences) {
let defRef;
if (currentProcedure) {
if (currentProcedure && currentProcedure.scope) {
defRef = currentProcedure.scope.find(upperName);

if (!defRef) {
Expand Down
30 changes: 30 additions & 0 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ module.exports = class Parser {
line: lineNumber
}

currentItem.range = {
start: lineNumber,
end: null
};

currentGroup = `structs`;

// Expand the LIKEDS value if there is one.
Expand All @@ -588,6 +593,11 @@ module.exports = class Parser {
break;

case `END-DS`:
if (dsScopes.length > 0) {
const currentDs = dsScopes[dsScopes.length - 1];
currentDs.range.end = lineNumber;
}

if (dsScopes.length === 1) {
scope.structs.push(dsScopes.pop());
} else
Expand All @@ -613,8 +623,14 @@ module.exports = class Parser {

currentItem.readParms = true;

currentItem.range = {
start: lineNumber,
end: null
};

// Does the keywords include a keyword that makes end-ds useless?
if (currentItem.keywords.some(keyword => oneLineTriggers[`DCL-PR`].some(trigger => keyword.startsWith(trigger)))) {
currentItem.range.end = lineNumber;
scope.procedures.push(currentItem);
resetDefinition = true;
}
Expand All @@ -626,6 +642,7 @@ module.exports = class Parser {

case `END-PR`:
if (currentItem && currentItem.type === `procedure`) {
currentItem.range.end = lineNumber;
scope.procedures.push(currentItem);
resetDefinition = true;
}
Expand Down Expand Up @@ -996,6 +1013,11 @@ module.exports = class Parser {
line: lineNumber
}

currentItem.range = {
start: lineNumber,
end: null
};

expandDs(file, currentItem);

currentGroup = `structs`;
Expand All @@ -1014,6 +1036,11 @@ module.exports = class Parser {
path: file,
line: lineNumber
}

currentItem.range = {
start: lineNumber,
end: null
};

currentGroup = `procedures`;
scope.procedures.push(currentItem);
Expand All @@ -1034,6 +1061,7 @@ module.exports = class Parser {
break;

default:
// No type, must be either a struct subfield OR a parameter
if (!currentItem) {
switch (currentGroup) {
case `structs`:
Expand Down Expand Up @@ -1082,6 +1110,8 @@ module.exports = class Parser {
currentItem.subItems[currentItem.subItems.length - 1].keywords.push(Fixed.getPrettyType(dSpec), ...dSpec.keywords);
}
}

currentItem.range.end = lineNumber;
}
break;
}
Expand Down

0 comments on commit 6e3d5a2

Please sign in to comment.