UNPKG

fish-lsp

Version:

LSP implementation for fish/fish-shell

135 lines (134 loc) 5.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Location = exports.Position = exports.Range = void 0; const LSP = __importStar(require("vscode-languageserver")); const tree_sitter_1 = require("./tree-sitter"); var Range; (function (Range) { Range.create = (start, end) => LSP.Range.create(start, end); Range.is = (value) => LSP.Range.is(value); Range.fromTextSpan = (span) => Range.fromLocations(span.start, span.end); Range.toTextSpan = (range) => ({ start: Position.toLocation(range.start), end: Position.toLocation(range.end), }); Range.fromLocations = (start, end) => LSP.Range.create(Math.max(0, start.line - 1), Math.max(start.offset - 1, 0), Math.max(0, end.line - 1), Math.max(0, end.offset - 1)); function intersection(one, other) { const start = Position.Max(other.start, one.start); const end = Position.Min(other.end, one.end); if (Position.isAfter(start, end)) { return undefined; } return LSP.Range.create(start, end); } Range.intersection = intersection; function isAfter(one, other) { return Position.isAfter(one.end, other.end) || Position.isAfter(one.end, other.start) && Position.isBeforeOrEqual(one.start, other.start); } Range.isAfter = isAfter; })(Range || (exports.Range = Range = {})); var Position; (function (Position) { Position.create = (line, character) => LSP.Position.create(line, character); Position.is = (value) => LSP.Position.is(value); Position.fromLocation = (fishlocation) => { return { line: Math.max(fishlocation.line - 1, 0), character: Math.max(fishlocation.offset - 1, 0), }; }; Position.toLocation = (position) => ({ line: position.line + 1, offset: position.character + 1, }); function Min(...positions) { if (!positions.length) { return undefined; } let result = positions.pop(); for (const p of positions) { if (isBefore(p, result)) { result = p; } } return result; } Position.Min = Min; function isBefore(one, other) { if (one.line < other.line) { return true; } if (other.line < one.line) { return false; } return one.character < other.character; } Position.isBefore = isBefore; function Max(...positions) { if (!positions.length) { return undefined; } let result = positions.pop(); for (const p of positions) { if (isAfter(p, result)) { result = p; } } return result; } Position.Max = Max; function isAfter(one, other) { return !isBeforeOrEqual(one, other); } Position.isAfter = isAfter; function isBeforeOrEqual(one, other) { if (one.line < other.line) { return true; } if (other.line < one.line) { return false; } return one.character <= other.character; } Position.isBeforeOrEqual = isBeforeOrEqual; function fromSyntaxNode(node) { return { start: Position.create(node.startPosition.row, node.endPosition.column), end: Position.create(node.endPosition.row, node.endPosition.column), }; } Position.fromSyntaxNode = fromSyntaxNode; })(Position || (exports.Position = Position = {})); var Location; (function (Location) { Location.create = (uri, range) => LSP.Location.create(uri, range); Location.is = (value) => LSP.Location.is(value); Location.fromTextSpan = (resource, fishTextSpan) => LSP.Location.create(resource, Range.fromTextSpan(fishTextSpan)); function equals(one, other) { return one.uri === other.uri && Range.is(one.range) && Range.is(other.range) && (0, tree_sitter_1.equalRanges)(one.range, other.range); } Location.equals = equals; })(Location || (exports.Location = Location = {}));