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

Feature Request: Ignore and warn unrecognized syntax and continue formatting the text #37

Open
Ebola-Chan-bot opened this issue Sep 22, 2024 · 5 comments

Comments

@Ebola-Chan-bot
Copy link

Ebola-Chan-bot commented Sep 22, 2024

Describe the Feature

Provides an extension option to ignore unrecognized syntax instead of reporting an error.

Why do you want this feature?

I know that there are many common PROCEDURE syntax that the extension will not support in a short time. But can we ignore and warn these unsupported syntax for a while, instead of just reporting an error and giving up formatting the whole text?

In any case, you are a code formatter, not a syntax checker. As far as I know, the general practice in the field of code formatters is that you should not require the code to be completely well-formed, but to format those well-formed parts as much as possible.

I think you can just skip and warn when you encounter syntax that you don't recognize and start over from the next semicolon. Would this logic be difficult to implement?

@nene
Copy link
Owner

nene commented Sep 22, 2024

Unfortunately this would be pretty difficult to implement. It's not so much a problem with the prettier plugin, but rather with the parser. Also, while this might not be common behavior of many formatters, it's how the core Prettier itself works. When you give it syntactically incorrect JavaScript, it will fail to format it.

@Ebola-Chan-bot
Copy link
Author

But the right to determine whether the syntax is correct is in your hands, isn't it?

Error: Syntax Error: Unexpected "PROCEDURE"
Was expecting to see: "EXTERNAL", "FOREIGN", "FULLTEXT", "GLOBAL", "INDEX", "LOCAL", "MATERIALIZED", "RECURSIVE", "SEARCH", "SNAPSHOT", "SPATIAL", "TABLE", "TEMP", "TEMPORARY", "TRIGGER", "UNIQUE", "UNLOGGED", "VECTOR", "VIEW", "VIRTUAL", or whitespace
--> c:\Users\vhtmf\Documents\MATLAB\MATLAB-Extension\+MATLAB\+Database\安装存储过程\_MATLAB_反序列化.sql:2:12
  |
2 | OR REPLACE PROCEDURE `_MATLAB_反序列化` (

From the log I can see that you listed some acceptable keywords, which did not include the actual keyword encountered so the error. I wonder if there should be an inner logical structure like CASE-WHEN? Then you can just add an ELSE branch to handle all the cases that are not in the list: no processing, output as-is. Don't let Prettier know there may be syntax errors.
An alternative workaround is prettier-ignore. Prettier appears to have provided a way of using special comments to mark pieces of code that should not be processed. However, your plugin doesn't seem to support it yet.

@nene
Copy link
Owner

nene commented Sep 22, 2024

But the right to determine whether the syntax is correct is in your hands, isn't it?

Correct. I also maintain the parser.

Regarding the specific error. It would be helpful if you provided the actual code that's causing you problems. Also, please state which SQL dialect you're using - it's hard for me to guess. The CREATE PROCEDURE syntax is supported for PostgreSQL and BigQuery.

An alternative workaround is prettier-ignore. Prettier appears to have provided a way of using special comments to mark pieces of code that should not be processed. However, your plugin doesn't seem to support it yet.

While it's true that this plugin doesn't yet support these ignore comments, I should point out that even in official Prettier, these comments only work when the parser is able to fully parse the code.

@Ebola-Chan-bot
Copy link
Author

I want to CREATE PROCEDURE for MariaDB. But as I understand it, from what you're saying, plugins of Prettier family are either fully applicable or not applicable at all, impossible to be in a state of partially applicable for a while… Long code with just one unsupported keyword disables the entire formatter… extremely unrobust…

@nene
Copy link
Owner

nene commented Sep 23, 2024

Yes, that's the downside of this architecture. That's why the support of MariaDB is also labeled "Experimental! expect crashes".

There are other SQL formatting tools out there which don't have this limitation.

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

No branches or pull requests

2 participants