Skip to content

Conversation

@toinehartman
Copy link
Member

@toinehartman toinehartman commented Nov 11, 2025

When the developer creates a Rascal file from within VS Code, automatically fill in the module header.

Recording 2025-11-12 112103

Closes #869

@toinehartman toinehartman marked this pull request as ready for review November 12, 2025 17:00
Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

This is heading in the right direction, it does need some extra love.

.thenApply(edits -> DocumentChanges.translateDocumentChanges(this, edits))
.thenCompose(wsEdit -> wsEdit.getDocumentChanges().isEmpty()
? null
: availableClient().applyEdit(new ApplyWorkspaceEditParams(wsEdit, "Auto-insert module headers")))
Copy link
Member

Choose a reason for hiding this comment

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

Could we mark these as needing a review? such that a user can see that this is happening, and accept it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, but then we should do #872 first (or hack it in Java here, which I am not a proponent of)

Copy link
Member

Choose a reason for hiding this comment

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

or finish this one, and add it after #872 is done

for (f <- newFiles) {
try {
// check if file is empty
if (!(f.extension == "rsc" && exists(f) && isBlank(f))) {
Copy link
Member

Choose a reason for hiding this comment

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

how about we check if there is a module <...> in there? as a user might already be typing?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? Aren't we out of luck when there are any contents anyway? Trying to race with a typing user seems tricky.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I was thinking more about if paste a new rascal file, so the copy already has code in there, but the wrong one?

But agreed, it might be more painful, so better only do it in empty files.

try {
// Test if the qualified name is valid
parse(#QualifiedName, qname);
return "module <qname>\n\n// TODO Auto-generated module contents.\n";
Copy link
Member

Choose a reason for hiding this comment

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

\n might not be the right newline for the current open editor tab. Would it not be simpler to either generate 2 text edits, one for line 1 and one for line 2?

Next to this: wat does "// TODO Auto-generated module contents mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good, idea, and I tried this. Unfortunately, we cannot use edits to add to non-existing lines.

Copy link
Member

Choose a reason for hiding this comment

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

you cannot insert a new line using a text edit? that seems weird?

Copy link
Member Author

Choose a reason for hiding this comment

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

We'll, an edit is just a replace. For an insert, the replace range should have start == end. I'll check how newlines are treated. Maybe VS Code maps them to the editor default anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

My VS Code converts the newlines to the editor setting when the file is saved. So, is this really a concern in that case?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but that comment line should be removed, or heavily rephrased , as the current version doesn't make sense to a user. (Unless they recognize the pattern from java functions where a return value is generated that the user should change)

This was referenced Nov 13, 2025
@sonarqubecloud
Copy link

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.

Add template for new Rascal files

2 participants