UNPKG

flink-sql-language-server

Version:

A LSP-based language server for Apache Flink SQL

188 lines (187 loc) 6.8 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.rangeFromContext = rangeFromContext; exports.positionInRange = positionInRange; exports.rangeInRange = rangeInRange; exports.rangeDistance = rangeDistance; exports.toDiagnosticSeverity = toDiagnosticSeverity; exports.toFoldingRange = toFoldingRange; exports.instanceOfRange = instanceOfRange; exports.toCompletionItem = toCompletionItem; const lsp = __importStar(require("vscode-languageserver")); function rangeFromContext(ctx) { const stop = ctx.stop ?? ctx.start; return { start: { line: ctx.start.line - 1, character: ctx.start.charPositionInLine }, end: { line: stop.line - 1, character: stop.charPositionInLine + (stop.stopIndex - stop.startIndex + 1) } }; } function positionInRange(document, position, range) { const currentOffset = document.offsetAt(position); const startOffset = document.offsetAt(range.start); const endOffset = document.offsetAt(range.end); return startOffset <= currentOffset && currentOffset <= endOffset; } function rangeInRange(document, range1, range2) { const startOffset1 = document.offsetAt(range1.start); const endOffset1 = document.offsetAt(range1.end); const startOffset2 = document.offsetAt(range2.start); const endOffset2 = document.offsetAt(range2.end); return startOffset1 <= startOffset2 && endOffset1 >= endOffset2; } function rangeDistance(document, range1, range2) { const startOffset1 = document.offsetAt(range1.start); const endOffset1 = document.offsetAt(range1.end); const startOffset2 = document.offsetAt(range2.start); const endOffset2 = document.offsetAt(range2.end); return Math.abs(startOffset1 - startOffset2) + Math.abs(endOffset1 - endOffset2); } function toDiagnosticSeverity(category) { switch (category) { case 'error': return lsp.DiagnosticSeverity.Error; case 'warning': return lsp.DiagnosticSeverity.Warning; case 'suggestion': return lsp.DiagnosticSeverity.Hint; default: return lsp.DiagnosticSeverity.Error; } } function toFoldingRange(range, kind = lsp.FoldingRangeKind.Region) { return lsp.FoldingRange.create(range.start.line, range.end.line, range.start.character, range.end.character, kind); } function instanceOfRange(obj) { return 'start' in obj && 'end' in obj; } function toCompletionItem(type, label, insertText, detail, documentation) { switch (type) { case 'catalog': return { kind: lsp.CompletionItemKind.Class, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `AAA${label}`, documentation, detail, data: 'catalog' }; case 'database': return { kind: lsp.CompletionItemKind.Enum, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `BAA${label}`, documentation, detail, data: 'database' }; case 'table': return { kind: lsp.CompletionItemKind.EnumMember, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `CBA${label}`, documentation, detail, data: 'table' }; case 'column': return { kind: lsp.CompletionItemKind.Field, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `DAA${label}`, documentation, detail, data: 'column' }; case 'view': return { kind: lsp.CompletionItemKind.EnumMember, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `CAA${label}`, documentation, detail, data: 'view' }; case 'model': return { kind: lsp.CompletionItemKind.EnumMember, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `CAB${label}`, documentation, detail, data: 'model' }; case 'function': return { kind: lsp.CompletionItemKind.Property, label, insertText: `\`${insertText}\``, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `EAA${label}`, documentation, detail, data: 'function' }; case 'built-in': return { kind: lsp.CompletionItemKind.Function, label, insertText, insertTextFormat: lsp.InsertTextFormat.Snippet, sortText: `FAA${label}`, documentation, detail, data: 'function' }; } }