-
Notifications
You must be signed in to change notification settings - Fork 75
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
Added context menu command to create new worksheet #183
Conversation
c033992
to
a933a8d
Compare
Looks cool! Thanks @alekseiAlefirov ! I am wondering if we should have a separate TAB with also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool! I wonder if we can generalize this feature to more kinds of files than just worksheets 🤔 it would be nice to make it work more similarly to "New" in IntelliJ with options to create a Scala file, worksheets, maybe test file (automatically inferring the matching test target), etc
@olafurpg , can you please elaborate on test file, how it should work? |
|
It's just an idea. It would be good to be able to at least handle a growing number of file kinds |
I agree it would be really good to have a couple of possible file templates, but if it's not yet supported sensibly within vs code then I agree we can start with this one. Although we could prepare a couple of commands within Metals itself. |
My concern is that the "Create Scala worksheet" command will demand too much attention and this approach isn't scalable to a large number of file kinds. I would prefer instead to expose this feature only as a command and a button in the Metals tree view (maybe under "build" explorer 🤔 ) |
I think we need to put it in the explorer - people are already super confused how to create that. I fear a button in the TreeView will too hidden and we will not achieve anything of the original purpose. We can just have the basic file kinds for now: |
How about having a single "New Scala file" button that opens a quick open dialogue for the available options? |
I agree the button should be available in the context menu, it would not be discoverable in the tree view |
Context menu changed to support creating new scala class: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, great work! I love the direction this is taking.
Comments here basically the same as in the server PR - we should reduce it all to a single level and we can jsut send an object via parameters.
src/extension.ts
Outdated
return withName(name => { | ||
client.sendRequest(ExecuteCommandRequest.type, { | ||
command: "new-scala-class", | ||
arguments: [dir, name, classKindPick.kind] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to have an object as an argument here and we can reduce it all to a single pick. Worksheet/object/trait/class together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
a9c3680
to
c9ead1f
Compare
2a61ae7
to
64d82b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@gabro would you be able to review the PR? I don't trust myself when it comes to typescript 😅
src/extension.ts
Outdated
const worksheetPick = { label: "Worksheet", kind: "worksheet" }; | ||
|
||
return window | ||
.showQuickPick( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of implementing the quick pick here, I think it would be nice to add a new LSP extension so the Metals server can open a quick pick. We can use window/showMessageRequest as a fallback.
I have tried to follow the principle of avoiding too much custom logic in the vscode client and allowing the server to push behavior instead. The benefit of this strategy is that we 1) we can reuse more code to support multiple editors and 2) next time we need a quick pick we may not have to update the client code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments about the implementation, but I too think we should move this to the server similarly to how we do for other extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olafurpg , so this way part of the logic for the dialog about a new file (it's kind and name) is going to be transferred to the server and inside of the new-scala-file command execution. Dialog parts can be cancelled, so I have a question - how this should be handled by the command? Currently it returns a string/URI of the newly created file. Would using null in case of cancellation be alright for this? Or the request should finish with failure? Or instead of just string as the return type, we can use some Cancelable
interface / generic container with it inside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the command “create new scala file” is sent to the server with a directory as the argument (or something like that) then I think it doesn’t matter what Metals returns. Metals already knows how to do the quick pick, do input box, apply workspace edit and also change the focused window (goto locations, it’s used in tree view protocol). Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory argument can be optional, for example when triggered via the command palette. Metals already knows the focused document.
src/extension.ts
Outdated
// NOTE(aleksei): I would return workspace folder here, but not sure if there's API for that. | ||
// Moving this funcitonality to server. | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving stuff to the server makes sense, but I would change this note to something more "final".
Also, what API are you looking for? workspace.workspaceFolders[0]
should give you what you want
src/protocol.ts
Outdated
export interface MetalsNewScalaFileParams { | ||
directory?: string; | ||
name: string; | ||
kind: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this kind be more specific?
kind: string; | |
kind: 'class' | 'object' | 'trait' | 'package-object' | 'worksheet' ; |
src/extension.ts
Outdated
const worksheetPick = { label: "Worksheet", kind: "worksheet" }; | ||
|
||
return window | ||
.showQuickPick( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments about the implementation, but I too think we should move this to the server similarly to how we do for other extensions.
a97fc87
to
1aab277
Compare
|
6421ba9
to
47f5838
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I think we can merge this as soon as we do the release.
…w-scala-file removed
Issue: #179
(PR for the server: scalameta/metals#1339)
From the explorer context menu:
From Command Palette: