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

Move custom indentation rules to vscode-scala-syntax instead of overwriting its rules #512

Open
smarter opened this issue Mar 1, 2021 · 12 comments

Comments

@smarter
Copy link

smarter commented Mar 1, 2021

Currently metals-vscode calls setLanguageConfiguration to provide indentation rules for scaladoc:

function enableScaladocIndentation() {
// Adapted from:
// https://github.com/Microsoft/vscode/blob/9d611d4dfd5a4a101b5201b8c9e21af97f06e7a7/extensions/typescript/src/typescriptMain.ts#L186
languages.setLanguageConfiguration("scala", {
indentationRules: {
// ^(.*\*/)?\s*\}.*$
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
// ^.*\{[^}"']*$
increaseIndentPattern: /^.*\{[^}"']*$/,
},
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
onEnterRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: " * " },
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: " * " },
},
{
// e.g. * ...| Javadoc style
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: "* " },
},
{
// e.g. * ...| Scaladoc style
beforeText: /^(\t|(\ \ ))*\*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: "* " },
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 },
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 },
},
],
});
}

The problem with that is that it overwrites any rules set for the scala language by vscode-scala-syntax. Currently there isn't any but we would like to add Scala 3 indentation rules there, see scala/vscode-scala-syntax#179. Step 1 is to get a language-configuration.json in vscode-scala-syntax with the scaladoc rules, step 2 will be to remove these rules from metals-vscode.

@tgodzik
Copy link
Contributor

tgodzik commented Mar 1, 2021

Thanks for reporting! For sure it makes sense to move the indentation rules to scala-syntax. Do you plan on adding the language configuration for Dotty there or should we take ownership of the full effort?

@smarter
Copy link
Author

smarter commented Mar 2, 2021

should we take ownership of the full effort?

Please go ahead and do that if you're interested!

@tgodzik
Copy link
Contributor

tgodzik commented Mar 2, 2021

I will put it on the list, but I've got some things that are more urgent (migrating Bloop to newest zinc 😨 )

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2022

I tried some of the indentation rules and it seems we cannot use them as those rules expect to have indent as well as deindent pairs. Wit optional braces this will not work, since there can be no end marker. I did add some additional rules about increasing indentation though and that seems to work for now.

@tgodzik tgodzik closed this as completed Jan 20, 2022
@smarter
Copy link
Author

smarter commented Jan 20, 2022

I don't understand why this issue was closed. Regardless of which rules should be used the problem here is that metals-vscode overwrites any rule set by vscode-scala-syntax. The solution is to move all rules to vscode-scala-syntax where we can then evolve things.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2022

I only added some simple onEnterRules here https://github.com/scalameta/metals-vscode/blob/main/src/extension.ts#L1181-L1196

I am not sure if we should migrate it all to Scala syntax? I will mention the changes in the other issue, but this anyway needs to be done first in vscode-syntax.

@smarter
Copy link
Author

smarter commented Jan 20, 2022

I am not sure if we should migrate it all to Scala syntax?

I'm pretty sure we should, this is about syntax support and is completely independent of metals.

@smarter
Copy link
Author

smarter commented Jan 20, 2022

Especially now that scala is indentation-based, it's important that editors support scala editing correctly regardless of whether metals is enabled or not (for example, when editing code in a web-based version of vscode where metals cannot be run)

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2022

I commented on the other issue as the actual work is required in the syntax repo.

@smarter
Copy link
Author

smarter commented Jan 20, 2022

Work is required in both repositories as mentioned in this issue:

Step 1 is to get a language-configuration.json in vscode-scala-syntax with the scaladoc rules, step 2 will be to remove these rules from metals-vscode.

So I believe this issue should be kept open. I haven't worked on step 1 since you mentioned you were going to do it in an earlier comment in this issue.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2022

I figured the issue was no longer relevant since we are using different rules, I can reopen it.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2022

Sorry about closing prematurely, I was bit tired and that got me cranky + in a mood to close old issues 😅

kasiaMarek pushed a commit to kasiaMarek/metals-vscode that referenced this issue Mar 29, 2023
…rn/types/node-18.11.3

chore(deps-dev): bump @types/node from 18.11.2 to 18.11.3
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