-
Notifications
You must be signed in to change notification settings - Fork 57
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
Code action: Extract module to file #983
Conversation
Printf.printf "%s\nnewText:\n%s<--here\n%s%s\n" | ||
(Protocol.stringifyRange range) | ||
indent indent newText))) | ||
|> List.iter (fun dc -> |
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 section just improves the test output a bit now that we have several document change actions.
type createFileOptions = {overwrite: bool option; ignoreIfExists: bool option} | ||
type createFile = {uri: string; options: createFileOptions option} | ||
|
||
type documentChange = | ||
| TextDocumentEdit of textDocumentEdit | ||
| CreateFile of createFile | ||
|
||
type codeActionEdit = {documentChanges: documentChange list} |
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.
These types are modelled after their LSP equivalents: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEdit
analysis/src/Xform.ml
Outdated
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 changes in this file are how you wire up a new code action. Essentially, you create an AST iterator that's responsible for "reacting" to anything you want to add code actions for. You then build a code action, and extract the information you need.
There are a few helpers like printStandaloneStructure
and printExpr
etc that are designed to help you print modified code in a way that makes it fit in as good as possible formatting wise in the current file.
Also note that this code action doesn't need to look up any types or any project specific things. It only operates on the raw AST. That makes it cheap. But, there are code actions that need type information to work (exhaustive switch is one example), and that works perfectly well too.
* code action for extracting a module to a new file * make sure comments are retained * fix broken serialization * changelog
Adds a code action to extract a module to a separate file.