-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not show duplicate actions. (#2528)
- Loading branch information
Showing
3 changed files
with
175 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Position } from 'vscode-languageserver'; | ||
|
||
/** | ||
* Compares two positions | ||
* @param a | ||
* @param b | ||
* @returns | ||
* negative - a < b | ||
* zero - a == b | ||
* positive a > b | ||
*/ | ||
export function compare(a: Position, b: Position): number { | ||
return a.line - b.line || a.character - b.character; | ||
} | ||
|
||
/** | ||
* Check if two positions are equivalent. | ||
* @param a - Position | ||
* @param b - Position | ||
* @returns true if they represent the same position. | ||
*/ | ||
export function equal(a: Position, b: Position): boolean { | ||
return a === b || compare(a, b) === 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Range } from 'vscode-languageserver'; | ||
|
||
import * as UtilPosition from './position'; | ||
|
||
export function intersect(a: Range, b: Range): Range | undefined { | ||
if (a === b) return a; | ||
|
||
const start = UtilPosition.compare(a.start, b.start) >= 0 ? a.start : b.start; | ||
const end = UtilPosition.compare(a.end, b.end) <= 0 ? a.end : b.end; | ||
|
||
return UtilPosition.compare(start, end) > 0 ? undefined : { start, end }; | ||
} | ||
|
||
/** | ||
* Check if two ranges are equivalent. | ||
* @param a - Range | ||
* @param b - Range | ||
* @returns true if they are equivalent. | ||
*/ | ||
export function equal(a: Range, b: Range): boolean { | ||
return UtilPosition.equal(a.start, b.start) && UtilPosition.equal(a.end, b.end); | ||
} | ||
|
||
/** | ||
* Check if `b` is fully contained in `a`. | ||
* @param a - Outer Range | ||
* @param b - Inner Range | ||
* @returns | ||
*/ | ||
export function contains(a: Range, b: Range): boolean { | ||
const intersection = intersect(a, b); | ||
return (intersection && equal(intersection, b)) || false; | ||
} |