Skip to content

Commit 3220f5b

Browse files
committed
Revert
1 parent f5bb722 commit 3220f5b

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

client/src/services/events.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { extension } from '../state';
33
import { updateStateMachine } from './state-machine';
44
import { SELECTION_DEBOUNCE_MS } from '../utils/constants';
55
import { getSelectionContextVariables, normalizeRange } from './context';
6-
import { normalizeFilePath } from '../utils/utils';
6+
import { normalizeFilePath, toRange } from '../utils/utils';
77
import { updateErrorAtCursor } from './diagnostics';
88
import type { Range } from '../types/context';
99

@@ -61,13 +61,8 @@ export async function onSelectionChange(event: vscode.TextEditorSelectionChangeE
6161
*/
6262
function handleContextUpdate(selection: vscode.Selection) {
6363
if (!extension.file || !extension.context) return;
64-
const range: Range = {
65-
lineStart: selection.start.line,
66-
colStart: selection.start.character,
67-
lineEnd: selection.end.line,
68-
colEnd: selection.end.character
69-
}
70-
const normalizedRange = normalizeRange(range);
64+
65+
const normalizedRange = normalizeRange(toRange(selection));
7166
const { allVars, visibleVars } = getSelectionContextVariables(extension.file, normalizedRange);
7267
extension.currentSelection = normalizedRange;
7368
extension.context.visibleVars = visibleVars;

client/src/services/hover.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import { extension } from '../state';
33
import type { Range, LJVariable } from '../types/context';
44
import { getSelectionContextVariables } from './context';
5-
import { getOriginalVariableName, normalizeFilePath } from '../utils/utils';
5+
import { getOriginalVariableName, normalizeFilePath, toRange } from '../utils/utils';
66

77
/**
88
* Initializes hover provider for LiquidJava diagnostics
@@ -37,12 +37,7 @@ function getHoveredVariable(document: vscode.TextDocument, position: vscode.Posi
3737

3838
const hoveredWord = document.getText(wordRange);
3939
const file = normalizeFilePath(document.uri.fsPath);
40-
const hoveredRange: Range = {
41-
lineStart: position.line + 1,
42-
colStart: position.character + 1,
43-
lineEnd: position.line + 1,
44-
colEnd: position.character + 1
45-
}
40+
const hoveredRange = toRange(wordRange);
4641
const { allVars } = getSelectionContextVariables(file, hoveredRange);
4742
return allVars.find(variable => getOriginalVariableName(variable.name) === hoveredWord);
4843
}

client/src/utils/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ export function normalizeFilePath(fsPath: string): string {
142142
// uppercase windows drive letter (c:\ -> C:\)
143143
return path.normalize(fsPath).replace(/^([a-z]):\\/, (_, drive) => drive.toUpperCase() + ':\\');
144144
}
145+
146+
export function toRange(selection: vscode.Selection | vscode.Range): Range {
147+
return {
148+
lineStart: selection.start.line,
149+
colStart: selection.start.character,
150+
lineEnd: selection.end.line,
151+
colEnd: selection.end.character
152+
};
153+
}

0 commit comments

Comments
 (0)