Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to automatically disable language service on detected Non-TSQL files #18550

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

laurennat
Copy link
Collaborator

@laurennat laurennat commented Jan 9, 2025

PR for giving users an option to automatically disable the language service when the extension detects non T-Sql syntax/ keywords.

The bulk of github's detected line changes come from the added non t-sql keyword list.

tooManySyntaxErrosCase
languageServiceCase1

Copy link

github-actions bot commented Jan 9, 2025

PR Changes

Category Main Branch PR Branch Difference
Code Coverage 50.41% 50.46% $${\color{lightgreen} .05\% }$$
VSIX Size 12123 KB 12129 KB $${\color{lightgreen} 6 KB \space (0\%) }$$
Webview Bundle Size 3112 KB 3112 KB $${\color{lightgreen} 0 KB \space (0\%) }$$

@croblesm
Copy link
Contributor

croblesm commented Jan 9, 2025

Hi @laurennat just a quick comment about the prompt. Could you please update the text to say "non-SQL Server" instead of "MSSQL". Another option is to say "non-TSQL" as T-SQL is SQL Server SQL language name.

* Called by VS Code when a text document is changed.
* @param change The change event that was detected
*/
public async onDidChangeTextDocument(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some unit tests for this code in a follow up PR.

SwitchUnset = 2,
}

export function hasNonTSqlKeywords(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good candidate for some unit tests.

// This condition is true if there are any errors in the document
// from another sql language service
sources.length ||
docErrors.length >= 50 ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make this number configurable?

* and PostGreSql documentation that are not present in the TSQL documentation
* of keywords.
*/
export const keywords: Set<string> = new Set([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if these keywords appear in object names? It's possible for keywords like 'cost' to be used as object names. With the current logic, this might trigger the prompt. I'm not sure what the best solution would be, but it's something to consider.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should trim some likely candidates for object names from this list?

@@ -561,6 +561,9 @@ export let flavorDescriptionMssql = l10n.t(
export let flavorDescriptionNone = l10n.t(
"Disable intellisense and syntax error checking on current document",
);
export let autoDisableNonTSqlLanguageServicePrompt = l10n.t(
"Possible non-SQL Server SQL file detected. Automatically disable Intellisense for all non-SQL Server SQL files?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croblesm, can you help refine this string to make sure the branding references are correct? Also, I feel like saying "SQL" so many times makes it a bit confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you already did in another comment; thanks!

* and PostGreSql documentation that are not present in the TSQL documentation
* of keywords.
*/
export const keywords: Set<string> = new Set([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should trim some likely candidates for object names from this list?

export function hasNonTSqlKeywords(
text: string,
nonTSqlKeywords: Set<string>,
): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, I envisioned this happening inside the Parser itself or within STS, rather than at the VS Code layer. The Parser code is already parsing the entire document to identifying comments/literals/object names, and the STS code (see HandleSyntaxParseRequest) is enumerating errors.

I'm also concerned about the performance of using a slew of regexes on what could be a large script file. Have you tried this with a long script (e.g. a deployment script)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants