@514labs/moose-lsp 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -3584,11 +3584,11 @@ var require_main2 = __commonJS({
3584
3584
  DiagnosticSeverity3.Information = 3;
3585
3585
  DiagnosticSeverity3.Hint = 4;
3586
3586
  })(DiagnosticSeverity2 || (exports3.DiagnosticSeverity = DiagnosticSeverity2 = {}));
3587
- var DiagnosticTag;
3588
- (function(DiagnosticTag2) {
3589
- DiagnosticTag2.Unnecessary = 1;
3590
- DiagnosticTag2.Deprecated = 2;
3591
- })(DiagnosticTag || (exports3.DiagnosticTag = DiagnosticTag = {}));
3587
+ var DiagnosticTag2;
3588
+ (function(DiagnosticTag3) {
3589
+ DiagnosticTag3.Unnecessary = 1;
3590
+ DiagnosticTag3.Deprecated = 2;
3591
+ })(DiagnosticTag2 || (exports3.DiagnosticTag = DiagnosticTag2 = {}));
3592
3592
  var CodeDescription;
3593
3593
  (function(CodeDescription2) {
3594
3594
  function is(value) {
@@ -4375,18 +4375,18 @@ var require_main2 = __commonJS({
4375
4375
  }
4376
4376
  DocumentSymbol2.is = is;
4377
4377
  })(DocumentSymbol || (exports3.DocumentSymbol = DocumentSymbol = {}));
4378
- var CodeActionKind2;
4379
- (function(CodeActionKind3) {
4380
- CodeActionKind3.Empty = "";
4381
- CodeActionKind3.QuickFix = "quickfix";
4382
- CodeActionKind3.Refactor = "refactor";
4383
- CodeActionKind3.RefactorExtract = "refactor.extract";
4384
- CodeActionKind3.RefactorInline = "refactor.inline";
4385
- CodeActionKind3.RefactorRewrite = "refactor.rewrite";
4386
- CodeActionKind3.Source = "source";
4387
- CodeActionKind3.SourceOrganizeImports = "source.organizeImports";
4388
- CodeActionKind3.SourceFixAll = "source.fixAll";
4389
- })(CodeActionKind2 || (exports3.CodeActionKind = CodeActionKind2 = {}));
4378
+ var CodeActionKind3;
4379
+ (function(CodeActionKind4) {
4380
+ CodeActionKind4.Empty = "";
4381
+ CodeActionKind4.QuickFix = "quickfix";
4382
+ CodeActionKind4.Refactor = "refactor";
4383
+ CodeActionKind4.RefactorExtract = "refactor.extract";
4384
+ CodeActionKind4.RefactorInline = "refactor.inline";
4385
+ CodeActionKind4.RefactorRewrite = "refactor.rewrite";
4386
+ CodeActionKind4.Source = "source";
4387
+ CodeActionKind4.SourceOrganizeImports = "source.organizeImports";
4388
+ CodeActionKind4.SourceFixAll = "source.fixAll";
4389
+ })(CodeActionKind3 || (exports3.CodeActionKind = CodeActionKind3 = {}));
4390
4390
  var CodeActionTriggerKind;
4391
4391
  (function(CodeActionTriggerKind2) {
4392
4392
  CodeActionTriggerKind2.Invoked = 1;
@@ -219722,7 +219722,7 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
219722
219722
  init_cjs_shims();
219723
219723
  var path8 = __toESM(require("path"));
219724
219724
  var import_moose_sql_validator_wasm2 = require("@514labs/moose-sql-validator-wasm");
219725
- var import_node3 = __toESM(require_node3());
219725
+ var import_node4 = __toESM(require_node3());
219726
219726
 
219727
219727
  // ../../node_modules/.pnpm/vscode-languageserver-textdocument@1.0.12/node_modules/vscode-languageserver-textdocument/lib/esm/main.js
219728
219728
  init_cjs_shims();
@@ -220129,6 +220129,7 @@ async function loadClickHouseData(requestedVersion) {
220129
220129
  // src/codeActions.ts
220130
220130
  init_cjs_shims();
220131
220131
  var import_typescript = __toESM(require_typescript());
220132
+ var import_node = __toESM(require_node3());
220132
220133
 
220133
220134
  // src/formatting.ts
220134
220135
  init_cjs_shims();
@@ -220277,17 +220278,21 @@ function createFormatSqlEdit(sourceFile, node) {
220277
220278
  }
220278
220279
  function findTemplateNodeById(sourceFile, locationId) {
220279
220280
  let targetNode;
220281
+ function isSqlTag(tag) {
220282
+ if (import_typescript.default.isIdentifier(tag) && tag.text === "sql") return true;
220283
+ if (import_typescript.default.isPropertyAccessExpression(tag) && import_typescript.default.isIdentifier(tag.expression) && tag.expression.text === "sql" && (tag.name.text === "statement" || tag.name.text === "fragment")) {
220284
+ return true;
220285
+ }
220286
+ return false;
220287
+ }
220280
220288
  function visit(node) {
220281
- if (import_typescript.default.isTaggedTemplateExpression(node)) {
220282
- const tag = node.tag;
220283
- if (import_typescript.default.isIdentifier(tag) && tag.text === "sql") {
220284
- const start = sourceFile.getLineAndCharacterOfPosition(
220285
- node.template.getStart()
220286
- );
220287
- const id = `${sourceFile.fileName}:${start.line + 1}:${start.character + 1}`;
220288
- if (id === locationId) {
220289
- targetNode = node;
220290
- }
220289
+ if (import_typescript.default.isTaggedTemplateExpression(node) && isSqlTag(node.tag)) {
220290
+ const start = sourceFile.getLineAndCharacterOfPosition(
220291
+ node.template.getStart()
220292
+ );
220293
+ const id = `${sourceFile.fileName}:${start.line + 1}:${start.character + 1}`;
220294
+ if (id === locationId) {
220295
+ targetNode = node;
220291
220296
  }
220292
220297
  }
220293
220298
  if (!targetNode) {
@@ -220297,10 +220302,50 @@ function findTemplateNodeById(sourceFile, locationId) {
220297
220302
  visit(sourceFile);
220298
220303
  return targetNode;
220299
220304
  }
220305
+ function createDeprecationCodeActions(uri, diagnostics) {
220306
+ const actions = [];
220307
+ for (const diagnostic of diagnostics) {
220308
+ const data = diagnostic.data;
220309
+ if (data?.type !== "deprecated-sql-tag") continue;
220310
+ actions.push(
220311
+ {
220312
+ title: "Convert to 'sql.statement'",
220313
+ kind: import_node.CodeActionKind.QuickFix,
220314
+ diagnostics: [diagnostic],
220315
+ edit: {
220316
+ changes: {
220317
+ [uri]: [
220318
+ {
220319
+ range: diagnostic.range,
220320
+ newText: "sql.statement"
220321
+ }
220322
+ ]
220323
+ }
220324
+ }
220325
+ },
220326
+ {
220327
+ title: "Convert to 'sql.fragment'",
220328
+ kind: import_node.CodeActionKind.QuickFix,
220329
+ diagnostics: [diagnostic],
220330
+ edit: {
220331
+ changes: {
220332
+ [uri]: [
220333
+ {
220334
+ range: diagnostic.range,
220335
+ newText: "sql.fragment"
220336
+ }
220337
+ ]
220338
+ }
220339
+ }
220340
+ }
220341
+ );
220342
+ }
220343
+ return actions;
220344
+ }
220300
220345
 
220301
220346
  // src/diagnostics.ts
220302
220347
  init_cjs_shims();
220303
- var import_node = __toESM(require_node3());
220348
+ var import_node2 = __toESM(require_node3());
220304
220349
  function createLocationDiagnostic(location, validationError) {
220305
220350
  const uri = `file://${location.file}`;
220306
220351
  const range2 = {
@@ -220315,16 +220360,38 @@ function createLocationDiagnostic(location, validationError) {
220315
220360
  };
220316
220361
  const diagnostic = {
220317
220362
  range: range2,
220318
- severity: import_node.DiagnosticSeverity.Error,
220363
+ severity: import_node2.DiagnosticSeverity.Error,
220319
220364
  message: `Invalid SQL: ${validationError.message}`,
220320
220365
  source: "moose-sql"
220321
220366
  };
220322
220367
  return { uri, diagnostic };
220323
220368
  }
220369
+ function createDeprecationDiagnostic(location) {
220370
+ const uri = `file://${location.file}`;
220371
+ const range2 = {
220372
+ start: {
220373
+ line: location.tagLine - 1,
220374
+ character: location.tagColumn - 1
220375
+ },
220376
+ end: {
220377
+ line: location.tagLine - 1,
220378
+ character: location.tagEndColumn - 1
220379
+ }
220380
+ };
220381
+ const diagnostic = {
220382
+ range: range2,
220383
+ severity: import_node2.DiagnosticSeverity.Hint,
220384
+ tags: [import_node2.DiagnosticTag.Deprecated],
220385
+ message: "The 'sql' tag is deprecated. Use 'sql.statement' for complete SQL statements or 'sql.fragment' for SQL expressions and conditions.",
220386
+ source: "moose-sql",
220387
+ data: { type: "deprecated-sql-tag" }
220388
+ };
220389
+ return { uri, diagnostic };
220390
+ }
220324
220391
 
220325
220392
  // src/hover.ts
220326
220393
  init_cjs_shims();
220327
- var import_node2 = __toESM(require_node3());
220394
+ var import_node3 = __toESM(require_node3());
220328
220395
  function getWordAtPosition(text, position) {
220329
220396
  if (position < 0 || position > text.length) {
220330
220397
  return "";
@@ -220497,7 +220564,7 @@ function createHoverContent(info, data) {
220497
220564
  }
220498
220565
  }
220499
220566
  return {
220500
- kind: import_node2.MarkupKind.Markdown,
220567
+ kind: import_node3.MarkupKind.Markdown,
220501
220568
  value: parts.join("\n\n")
220502
220569
  };
220503
220570
  }
@@ -227643,7 +227710,11 @@ function createSqlLocation(filePath, text, startPosition, endPosition) {
227643
227710
  // 1-based
227644
227711
  endLine: endPosition.row + 1,
227645
227712
  endColumn: endPosition.column + 1,
227646
- templateText: text
227713
+ templateText: text,
227714
+ tagKind: "statement",
227715
+ tagLine: startPosition.row + 1,
227716
+ tagColumn: startPosition.column + 1,
227717
+ tagEndColumn: startPosition.column + 1
227647
227718
  };
227648
227719
  }
227649
227720
  function extractPythonSqlLocations(sourceCode, filePath) {
@@ -227805,6 +227876,14 @@ function isPythonFile(filePath) {
227805
227876
  function validateSqlLocations(sqlLocations, validateSql2, createDiagnostic) {
227806
227877
  const diagnosticsMap = /* @__PURE__ */ new Map();
227807
227878
  for (const location of sqlLocations) {
227879
+ if (location.tagKind === "bare") {
227880
+ const { uri, diagnostic } = createDeprecationDiagnostic(location);
227881
+ if (!diagnosticsMap.has(uri)) {
227882
+ diagnosticsMap.set(uri, []);
227883
+ }
227884
+ diagnosticsMap.get(uri)?.push(diagnostic);
227885
+ }
227886
+ if (location.tagKind === "fragment") continue;
227808
227887
  const preparedSql = prepareSqlForValidation(location.templateText);
227809
227888
  const result = validateSql2(preparedSql);
227810
227889
  if (!result.valid && result.error) {
@@ -227821,23 +227900,43 @@ function validateSqlLocations(sqlLocations, validateSql2, createDiagnostic) {
227821
227900
  // src/sqlExtractor.ts
227822
227901
  init_cjs_shims();
227823
227902
  var import_typescript2 = __toESM(require_typescript());
227824
- function isMooseLibSqlTag(node, typeChecker) {
227903
+ function getMooseSqlTagKind(node, typeChecker) {
227825
227904
  const tag = node.tag;
227826
- if (!import_typescript2.default.isIdentifier(tag) || tag.text !== "sql") {
227827
- return false;
227905
+ let sqlIdentifier;
227906
+ let tagKind;
227907
+ if (import_typescript2.default.isIdentifier(tag) && tag.text === "sql") {
227908
+ sqlIdentifier = tag;
227909
+ tagKind = "bare";
227910
+ } else if (import_typescript2.default.isPropertyAccessExpression(tag) && import_typescript2.default.isIdentifier(tag.expression) && tag.expression.text === "sql") {
227911
+ const propName = tag.name.text;
227912
+ if (propName === "statement") {
227913
+ tagKind = "statement";
227914
+ } else if (propName === "fragment") {
227915
+ tagKind = "fragment";
227916
+ } else {
227917
+ return null;
227918
+ }
227919
+ sqlIdentifier = tag.expression;
227920
+ } else {
227921
+ return null;
227922
+ }
227923
+ const symbol = typeChecker.getSymbolAtLocation(sqlIdentifier);
227924
+ if (!symbol) {
227925
+ return tagKind;
227828
227926
  }
227829
- const symbol = typeChecker.getSymbolAtLocation(tag);
227830
- if (symbol?.declarations?.length) {
227831
- const isFromMooseLib = symbol.declarations.some((decl) => {
227927
+ const resolvedSymbol = symbol.flags & import_typescript2.default.SymbolFlags.Alias ? typeChecker.getAliasedSymbol(symbol) : symbol;
227928
+ if (resolvedSymbol?.declarations?.length) {
227929
+ const isFromMooseLib = resolvedSymbol.declarations.some((decl) => {
227832
227930
  const sourceFile = decl.getSourceFile();
227833
227931
  const fileName = sourceFile.fileName;
227834
227932
  return fileName.includes("moose-lib") || fileName.includes("@514labs/moose-lib") || fileName.includes("514labs/moose-lib") || fileName.includes("sqlHelpers");
227835
227933
  });
227836
227934
  if (isFromMooseLib) {
227837
- return true;
227935
+ return tagKind;
227838
227936
  }
227937
+ return null;
227839
227938
  }
227840
- return true;
227939
+ return tagKind;
227841
227940
  }
227842
227941
  function extractTemplateText2(template) {
227843
227942
  if (import_typescript2.default.isNoSubstitutionTemplateLiteral(template)) {
@@ -227849,11 +227948,15 @@ function extractTemplateText2(template) {
227849
227948
  }
227850
227949
  return text;
227851
227950
  }
227852
- function extractSqlLocation(node, sourceFile) {
227951
+ function extractSqlLocation(node, sourceFile, tagKind) {
227853
227952
  const start = sourceFile.getLineAndCharacterOfPosition(
227854
227953
  node.template.getStart()
227855
227954
  );
227856
227955
  const end = sourceFile.getLineAndCharacterOfPosition(node.template.getEnd());
227956
+ const tagStart = sourceFile.getLineAndCharacterOfPosition(
227957
+ node.tag.getStart()
227958
+ );
227959
+ const tagEnd = sourceFile.getLineAndCharacterOfPosition(node.tag.getEnd());
227857
227960
  return {
227858
227961
  id: `${sourceFile.fileName}:${start.line + 1}:${start.character + 1}`,
227859
227962
  file: sourceFile.fileName,
@@ -227863,14 +227966,21 @@ function extractSqlLocation(node, sourceFile) {
227863
227966
  // 1-based
227864
227967
  endLine: end.line + 1,
227865
227968
  endColumn: end.character + 1,
227866
- templateText: extractTemplateText2(node.template)
227969
+ templateText: extractTemplateText2(node.template),
227970
+ tagKind,
227971
+ tagLine: tagStart.line + 1,
227972
+ tagColumn: tagStart.character + 1,
227973
+ tagEndColumn: tagEnd.character + 1
227867
227974
  };
227868
227975
  }
227869
227976
  function extractSqlLocations(sourceFile, typeChecker) {
227870
227977
  const locations = [];
227871
227978
  function visit(node) {
227872
- if (import_typescript2.default.isTaggedTemplateExpression(node) && isMooseLibSqlTag(node, typeChecker)) {
227873
- locations.push(extractSqlLocation(node, sourceFile));
227979
+ if (import_typescript2.default.isTaggedTemplateExpression(node)) {
227980
+ const tagKind = getMooseSqlTagKind(node, typeChecker);
227981
+ if (tagKind !== null) {
227982
+ locations.push(extractSqlLocation(node, sourceFile, tagKind));
227983
+ }
227874
227984
  }
227875
227985
  import_typescript2.default.forEachChild(node, visit);
227876
227986
  }
@@ -227989,8 +228099,8 @@ function createTypeScriptService() {
227989
228099
  }
227990
228100
 
227991
228101
  // src/server.ts
227992
- var connection = (0, import_node3.createConnection)(import_node3.ProposedFeatures.all);
227993
- var documents = new import_node3.TextDocuments(TextDocument);
228102
+ var connection = (0, import_node4.createConnection)(import_node4.ProposedFeatures.all);
228103
+ var documents = new import_node4.TextDocuments(TextDocument);
227994
228104
  var mooseProjectRoot = null;
227995
228105
  var mooseProjectType = null;
227996
228106
  var tsService = null;
@@ -228259,14 +228369,14 @@ connection.onInitialize(
228259
228369
  capabilities: {
228260
228370
  textDocumentSync: {
228261
228371
  openClose: true,
228262
- change: import_node3.TextDocumentSyncKind.Full,
228372
+ change: import_node4.TextDocumentSyncKind.Full,
228263
228373
  // Full sync for as-you-type validation
228264
228374
  save: {
228265
228375
  includeText: true
228266
228376
  }
228267
228377
  },
228268
228378
  codeActionProvider: {
228269
- codeActionKinds: ["source.formatSql"]
228379
+ codeActionKinds: [import_node4.CodeActionKind.QuickFix, "source.formatSql"]
228270
228380
  },
228271
228381
  completionProvider: {
228272
228382
  triggerCharacters: [".", "(", " "],
@@ -228320,59 +228430,71 @@ connection.onCodeAction((params) => {
228320
228430
  if (!document2) return [];
228321
228431
  const filePath = new URL(params.textDocument.uri).pathname;
228322
228432
  if (!shouldValidateFile(filePath, mooseProjectRoot)) return [];
228323
- if (!isTypeScriptFile(filePath) || !tsService?.isHealthy()) return [];
228324
- try {
228325
- const sourceFile = tsService.getSourceFile(filePath);
228326
- if (!sourceFile) return [];
228327
- const sqlLocations = extractSqlLocations(
228328
- sourceFile,
228329
- tsService.getTypeChecker()
228330
- );
228331
- const location = findSqlTemplateAtPosition(
228332
- sqlLocations,
228333
- params.range.start.line,
228334
- params.range.start.character
228433
+ const actions = [];
228434
+ if (params.context.diagnostics.length > 0) {
228435
+ actions.push(
228436
+ ...createDeprecationCodeActions(
228437
+ params.textDocument.uri,
228438
+ params.context.diagnostics
228439
+ )
228335
228440
  );
228336
- if (!location) return [];
228337
- const node = findTemplateNodeById(sourceFile, location.id);
228338
- if (!node) return [];
228339
- const edit = createFormatSqlEdit(sourceFile, node);
228340
- if (!edit) return [];
228341
- return [
228342
- {
228343
- title: "Format SQL",
228344
- kind: `${import_node3.CodeActionKind.Source}.formatSql`,
228345
- edit: {
228346
- changes: {
228347
- [params.textDocument.uri]: [edit]
228441
+ }
228442
+ if (isTypeScriptFile(filePath) && tsService?.isHealthy()) {
228443
+ try {
228444
+ const sourceFile = tsService.getSourceFile(filePath);
228445
+ if (sourceFile) {
228446
+ const sqlLocations = extractSqlLocations(
228447
+ sourceFile,
228448
+ tsService.getTypeChecker()
228449
+ );
228450
+ const location = findSqlTemplateAtPosition(
228451
+ sqlLocations,
228452
+ params.range.start.line,
228453
+ params.range.start.character
228454
+ );
228455
+ if (location) {
228456
+ const node = findTemplateNodeById(sourceFile, location.id);
228457
+ if (node) {
228458
+ const edit = createFormatSqlEdit(sourceFile, node);
228459
+ if (edit) {
228460
+ actions.push({
228461
+ title: "Format SQL",
228462
+ kind: `${import_node4.CodeActionKind.Source}.formatSql`,
228463
+ edit: {
228464
+ changes: {
228465
+ [params.textDocument.uri]: [edit]
228466
+ }
228467
+ }
228468
+ });
228469
+ }
228348
228470
  }
228349
228471
  }
228350
228472
  }
228351
- ];
228352
- } catch {
228353
- return [];
228473
+ } catch {
228474
+ }
228354
228475
  }
228476
+ return actions;
228355
228477
  });
228356
228478
  function mapCompletionItemKind(kind) {
228357
228479
  switch (kind) {
228358
228480
  case "function":
228359
- return import_node3.CompletionItemKind.Function;
228481
+ return import_node4.CompletionItemKind.Function;
228360
228482
  case "aggregate_function":
228361
- return import_node3.CompletionItemKind.Method;
228483
+ return import_node4.CompletionItemKind.Method;
228362
228484
  case "table_function":
228363
- return import_node3.CompletionItemKind.Function;
228485
+ return import_node4.CompletionItemKind.Function;
228364
228486
  case "keyword":
228365
- return import_node3.CompletionItemKind.Keyword;
228487
+ return import_node4.CompletionItemKind.Keyword;
228366
228488
  case "data_type":
228367
- return import_node3.CompletionItemKind.TypeParameter;
228489
+ return import_node4.CompletionItemKind.TypeParameter;
228368
228490
  case "table_engine":
228369
- return import_node3.CompletionItemKind.Class;
228491
+ return import_node4.CompletionItemKind.Class;
228370
228492
  case "format":
228371
- return import_node3.CompletionItemKind.Constant;
228493
+ return import_node4.CompletionItemKind.Constant;
228372
228494
  case "setting":
228373
- return import_node3.CompletionItemKind.Property;
228495
+ return import_node4.CompletionItemKind.Property;
228374
228496
  default:
228375
- return import_node3.CompletionItemKind.Text;
228497
+ return import_node4.CompletionItemKind.Text;
228376
228498
  }
228377
228499
  }
228378
228500
  function toRustCompletionItem(rustItem, useSnippets) {
@@ -228382,10 +228504,10 @@ function toRustCompletionItem(rustItem, useSnippets) {
228382
228504
  if (rustItem.hasParams) {
228383
228505
  if (useSnippets) {
228384
228506
  insertText = `${rustItem.label}($1)$0`;
228385
- insertTextFormat = import_node3.InsertTextFormat.Snippet;
228507
+ insertTextFormat = import_node4.InsertTextFormat.Snippet;
228386
228508
  } else {
228387
228509
  insertText = `${rustItem.label}()`;
228388
- insertTextFormat = import_node3.InsertTextFormat.PlainText;
228510
+ insertTextFormat = import_node4.InsertTextFormat.PlainText;
228389
228511
  }
228390
228512
  }
228391
228513
  return {