Skip to content

Commit

Permalink
Fixes #327
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed May 1, 2024
1 parent 33126ac commit 0695e01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Fix issue [#324](https://github.com/intersystems/language-server/issues/324): Add intellisense for variables set to JSON literal constructors
- Fix issue [#325](https://github.com/intersystems/language-server/issues/325): Don't sort inherited `%%OID` members at the top of completion lists
- Fix issue [#326](https://github.com/intersystems/language-server/issues/326): Completion lists in an instance context should include ClassMethods and Parameters
- Fix issue [#327](https://github.com/intersystems/language-server/issues/327): Go to definition on routine label can go to the wrong location
- Parser changes:
- DP-430347: Track variables in routine procedure blocks
- DP-430473: Fix variable tracking with embedded SQL in routine procedure blocks
Expand Down
19 changes: 11 additions & 8 deletions server/src/providers/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ export async function onDefinition(params: TextDocumentPositionParams) {
const rtnText: string[] = await getTextForUri(newuri,server);
if (rtnText.length) {
// Loop through the file contents to find this label
var targetselrange = Range.create(Position.create(0,0),Position.create(0,0));
var targetrange = Range.create(Position.create(0,0),Position.create(0,0));
var targetselrange = Range.create(0,0,0,0);
var targetrange = Range.create(0,0,0,0);
var linect = 0;
for (let k = 0; k < rtnText.length; k++) {
if (linect > 0) {
Expand All @@ -617,9 +617,9 @@ export async function onDefinition(params: TextDocumentPositionParams) {
}
}
else if (
rtnText[k].slice(0,label.length) === label &&
rtnText[k].startsWith(label) &&
(
rtnText[k].trim().length === label.length || // The label is the whole line
rtnText[k].trimEnd().length == label.length || // The label is the whole line
/ |\t|\(/.test(rtnText[k].charAt(label.length)) || // The label is followed by space, tab or (
// The label is followed by a comment
rtnText[k].slice(label.length).startsWith(";") ||
Expand All @@ -629,7 +629,7 @@ export async function onDefinition(params: TextDocumentPositionParams) {
)
) {
// This is the label definition
targetselrange = Range.create(Position.create(k,0),Position.create(k,label.length));
targetselrange = Range.create(k,0,k,label.length);
targetrange.start = Position.create(k,0);
linect++;
}
Expand Down Expand Up @@ -675,17 +675,20 @@ export async function onDefinition(params: TextDocumentPositionParams) {
targetrange.end = Position.create(line+1,0);
break;
}
if (parsed[line].length > 0 && parsed[line][0].l == ld.cos_langindex && parsed[line][0].s == ld.cos_label_attrindex) {
if (
parsed[line].length > 0 && parsed[line][0].l == ld.cos_langindex &&
parsed[line][0].s == ld.cos_label_attrindex && parsed[line][0].p == 0
) {
// This is a label
if (linect > 0) {
// This is the first label following the one we needed the definition for, so cut off the preview range here
targetrange.end = Position.create(line,0);
break;
}
else {
const firstwordrange = Range.create(Position.create(line,parsed[line][0].p),Position.create(line,parsed[line][0].p+parsed[line][0].c));
const firstwordrange = Range.create(line,parsed[line][0].p,line,parsed[line][0].p+parsed[line][0].c);
const firstwordtext = doc.getText(firstwordrange);
if (firstwordtext === label) {
if (firstwordtext == label) {
// This is the correct label
targetselrange = firstwordrange;
targetrange.start = Position.create(line,0);
Expand Down

0 comments on commit 0695e01

Please sign in to comment.