Skip to content

Commit

Permalink
Validate specific group when editing
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 20, 2024
1 parent c8cce99 commit 96bab44
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/language/providers/problemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ export const problemProvider = [

workspace.onDidChangeTextDocument(e => {
const isSql = e.document.languageId === `sql`;
if (isSql && checkOnChange()) {
if (isSql && checkOnChange() && e.contentChanges.length > 0) {
if (currentTimeout) {
clearTimeout(currentTimeout);
}

currentTimeout = setTimeout(() => {
validateSqlDocument(e.document);
validateSqlDocument(e.document, e.document.offsetAt(e.contentChanges[0].range.start));
}, getCheckerTimeout());
}
})
];

async function validateSqlDocument(document: TextDocument) {
async function validateSqlDocument(document: TextDocument, specificStatement?: number) {
const checker = SQLStatementChecker.get();
if (remoteAssistIsEnabled() && checker) {
const content = document.getText();
Expand All @@ -92,12 +92,23 @@ async function validateSqlDocument(document: TextDocument) {
for (const group of allGroups) {
const range = getStatementRangeFromGroup(group);
if (range) {
if (specificStatement) {
// If specificStatement is outline this range, continue
if (specificStatement <= range[0] || specificStatement >= range[1]) {
continue;
}
}

statementRanges.push(range);
}
}

const sqlStatementContents = statementRanges.map(range => content.substring(range[0], range[1]));
const se = performance.now();
const syntaxChecked = await checker.checkMultipleStatements(sqlStatementContents);
const ee = performance.now();

console.log(`Syntax check took: ${ee - se}ms`);

if (syntaxChecked) {
if (syntaxChecked.length > 0) {
Expand Down

0 comments on commit 96bab44

Please sign in to comment.