Use an object type to represent Position
This commit is contained in:
@@ -141,13 +141,16 @@ function posInToken(pos: Position, token: TemplateToken): boolean {
|
||||
const tokenChar = pos.character + 1;
|
||||
|
||||
// Check lines
|
||||
if (r.start[0] > tokenLine || tokenLine > r.end[0]) {
|
||||
if (r.start.line > tokenLine || tokenLine > r.end.line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Position is within the token lines. Check character/column if pos line matches
|
||||
// start or end
|
||||
if ((r.start[0] === tokenLine && tokenChar < r.start[1]) || (r.end[0] === tokenLine && tokenChar > r.end[1])) {
|
||||
if (
|
||||
(r.start.line === tokenLine && tokenChar < r.start.column) ||
|
||||
(r.end.line === tokenLine && tokenChar > r.end.column)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -163,14 +166,14 @@ function onSameLine(pos: Position, key: TemplateToken, value: TemplateToken): bo
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.range.start[0] !== value.range.end[0]) {
|
||||
if (value.range.start.line !== value.range.end.line) {
|
||||
// Token occupies multiple lines, can't be an empty node
|
||||
return false;
|
||||
}
|
||||
|
||||
// TokenRange is one-based, Position is zero-based
|
||||
const posLine = pos.line + 1;
|
||||
if (posLine != value.range.start[0]) {
|
||||
if (posLine != value.range.start.line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export function mapRange(range: TokenRange | undefined): Range {
|
||||
|
||||
export function mapPosition(position: TokenPosition): Position {
|
||||
return {
|
||||
line: position[0] - 1,
|
||||
character: position[1] - 1
|
||||
line: position.line - 1,
|
||||
character: position.column - 1
|
||||
};
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ function getProviderContext(
|
||||
): WorkflowContext {
|
||||
const {parent, path} = findToken(
|
||||
{
|
||||
line: token.range!.start[0] - 1,
|
||||
character: token.range!.start[1] - 1
|
||||
line: token.range!.start.line - 1,
|
||||
character: token.range!.start.column - 1
|
||||
},
|
||||
root
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user