Skip to content

Commit

Permalink
Improvements to show a signature
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Sep 23, 2024
1 parent d6e287e commit 008e435
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/language/providers/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ export const hoverProvider = languages.registerHoverProvider({ language: `sql` }
if (result) {
if ('routine' in result) {
const routineOffset = ref.tokens[ref.tokens.length-1].range.end+1;
const callableRef = statementAt.getCallableDetail(routineOffset, false);
if (callableRef) {
const { currentCount } = getPositionData(callableRef, routineOffset);
const signatures = await DbCache.getCachedSignatures(callableRef.parentRef.object.schema, callableRef.parentRef.object.name);
const possibleSignatures = signatures.filter((s) => s.parms.length >= currentCount).sort((a, b) => a.parms.length - b.parms.length);
const signature = possibleSignatures.find((signature) => currentCount <= signature.parms.length);
if (signature) {
addRoutineMd(md, signature, result);
const callableRef = statementAt.getCallableDetail(routineOffset, false)
const signatures = await DbCache.getCachedSignatures(schema, ref.object.name);

if (signatures.length > 0) {
let chosenSignature: CallableSignature | undefined;
if (callableRef) {
const { currentCount } = getPositionData(callableRef, routineOffset);
const possibleSignatures = signatures.filter((s) => s.parms.length >= currentCount).sort((a, b) => a.parms.length - b.parms.length);
chosenSignature = possibleSignatures.find((signature) => currentCount <= signature.parms.length);
} else {
chosenSignature = signatures[0];
}

if (chosenSignature) {
addRoutineMd(md, chosenSignature, result);
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/language/sql/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export function formatSql(textDocument: string, options: FormatOptions = {}): st
const statementGroups: StatementGroup[] = document.getStatementGroups();

const eol = textDocument.includes(`\r\n`) ? `\r\n` : `\n`;
let prevType = StatementType.Unknown;

for (const statementGroup of statementGroups) {
let currentIndent = 0;
let prevType = statementGroup.statements[0].type;
for (let i = 0; i < statementGroup.statements.length; i++) {
const statement = statementGroup.statements[i];
const withBlocks = SQLTokeniser.createBlocks(statement.tokens);
Expand Down

0 comments on commit 008e435

Please sign in to comment.