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

Incorrect mapping for BEGIN and appropriate END keyword #85

Closed
gal20040 opened this issue May 23, 2022 · 5 comments
Closed

Incorrect mapping for BEGIN and appropriate END keyword #85

gal20040 opened this issue May 23, 2022 · 5 comments
Labels
sql Caused by the sql lexer

Comments

@gal20040
Copy link

gal20040 commented May 23, 2022

Description of the Issue

There is incorrect mapping for BEGIN and appropriate END keyword.

Steps to Reproduce the Issue

1.Check the following sql code

if (1=1)
begin
	select getdate() --1

	if (2=2)
	begin
		select getdate() --2
		
		if (3=3)
		begin
			select getdate() --3
		end
		
		select getdate() --4
	end

	select getdate() --5
end

image
2. Try to collapse outer BEGIN-END block by clicking '-' near BEGIN.

Expected Behavior

All code inside outer BEGIN-END block should be hide:
image
image

Actual Behavior

There is incorrect hiding of code between outer BEGIN and inner END:
image
image

image

@gal20040
Copy link
Author

Just to compare with actual correct behaviour in SSMS:
image
image

@nyamatongwe
Copy link
Member

Equivalent case:

select getdate()
begin
begin
end
end

The problem is that the select statement isn't seen as terminated so sqlStatesCurrentLine is MASK_INTO_SELECT_STATEMENT_OR_ASSIGNEMENT (0x200) for the rest of the file causing a double decrement at each end.

Adding a ; to the select select getdate(); gets it treated as terminated and the folds work.

@gal20040
Copy link
Author

gal20040 commented May 24, 2022

Adding a ; to the select select getdate(); gets it treated as terminated and the folds work.

Thanks for it! Good point!

@nyamatongwe
Copy link
Member

The sql lexer is most targeted at Oracle's SQL variant which requires semi-colons. Not handling invalid code isn't really a bug.
https://docs.oracle.com/cd/B14117_01/server.101/b10759/statements_10002.htm#SQLRF01702

There are other SQL variant lexers: mysql for MySQL and mssql for Microsoft SQL Server.

Here's the mssql lexer:
mssql_select_fold

@nyamatongwe
Copy link
Member

Closing. ; should be added for sql and mssql can be used when appropriate.

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

No branches or pull requests

2 participants