-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Got one example working. * Add unit tests * Extract re-usable logic into partial active patterns. * No focus tests
- Loading branch information
Showing
8 changed files
with
271 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/FsAutoComplete/CodeFixes/UpdateTypeAbbreviationInSignatureFile.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module FsAutoComplete.CodeFix.UpdateTypeAbbreviationInSignatureFile | ||
|
||
open FSharp.Compiler.Symbols | ||
open FSharp.Compiler.Syntax | ||
open FSharp.Compiler.Text | ||
open FsToolkit.ErrorHandling | ||
open Ionide.LanguageServerProtocol.Types | ||
open FsAutoComplete.CodeFix.Types | ||
open FsAutoComplete | ||
open FsAutoComplete.LspHelpers | ||
open FsAutoComplete.Patterns.SymbolUse | ||
|
||
let title = "Update type abbreviation in signature file" | ||
|
||
let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix = | ||
Run.ifDiagnosticByCode (Set.ofList [ "318" ]) (fun diagnostic codeActionParams -> | ||
asyncResult { | ||
let implFilePath = codeActionParams.TextDocument.GetFilePath() | ||
let implFileName = Utils.normalizePath implFilePath | ||
|
||
let! (implParseAndCheckResults: ParseAndCheckResults, _implLine: string, implSourceText: IFSACSourceText) = | ||
getParseResultsForFile implFileName (protocolPosToPos diagnostic.Range.Start) | ||
|
||
let mDiag = | ||
protocolRangeToRange implParseAndCheckResults.GetParseResults.FileName diagnostic.Range | ||
|
||
let implTypeName = | ||
(mDiag.Start, implParseAndCheckResults.GetParseResults.ParseTree) | ||
||> ParsedInput.tryPick (fun _ node -> | ||
match node with | ||
| SyntaxNode.SynTypeDefn(SynTypeDefn( | ||
typeInfo = SynComponentInfo(longId = [ typeIdent ]) | ||
typeRepr = SynTypeDefnRepr.Simple(simpleRepr = SynTypeDefnSimpleRepr.TypeAbbrev _; range = mBody))) when | ||
Range.equals typeIdent.idRange mDiag | ||
-> | ||
Some(typeIdent, mBody) | ||
| _ -> None) | ||
|
||
match implTypeName with | ||
| None -> return [] | ||
| Some(typeName, mImplBody) -> | ||
match implParseAndCheckResults.TryGetSymbolUseFromIdent implSourceText typeName with | ||
| Some(IsInSignature signatureLocation) -> | ||
let sigFilePath = $"%s{implFilePath}i" | ||
let sigFileName = Utils.normalizePath sigFilePath | ||
|
||
let sigTextDocumentIdentifier: TextDocumentIdentifier = | ||
{ Uri = $"%s{codeActionParams.TextDocument.Uri}i" } | ||
|
||
let! (sigParseAndCheckResults: ParseAndCheckResults, _sigLine: string, _sigSourceText: IFSACSourceText) = | ||
getParseResultsForFile sigFileName (Position.mkPos 1 0) | ||
|
||
let mSigTypeAbbrev = | ||
(signatureLocation.Start, sigParseAndCheckResults.GetParseResults.ParseTree) | ||
||> ParsedInput.tryPick (fun _path node -> | ||
match node with | ||
| SyntaxNode.SynTypeDefnSig(SynTypeDefnSig( | ||
typeInfo = SynComponentInfo(longId = [ typeIdent ]) | ||
typeRepr = SynTypeDefnSigRepr.Simple(repr = SynTypeDefnSimpleRepr.TypeAbbrev _; range = m))) when | ||
Range.equals typeIdent.idRange signatureLocation | ||
-> | ||
Some m | ||
| _ -> None) | ||
|
||
match mSigTypeAbbrev with | ||
| None -> return [] | ||
| Some mSigTypeAbbrev -> | ||
let newText = implSourceText.GetSubTextFromRange mImplBody | ||
|
||
return | ||
[ { SourceDiagnostic = None | ||
Title = title | ||
File = sigTextDocumentIdentifier | ||
Edits = | ||
[| { Range = fcsRangeToLsp mSigTypeAbbrev | ||
NewText = newText } |] | ||
Kind = FixKind.Fix } ] | ||
| _ -> return [] | ||
}) |
6 changes: 6 additions & 0 deletions
6
src/FsAutoComplete/CodeFixes/UpdateTypeAbbreviationInSignatureFile.fsi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module FsAutoComplete.CodeFix.UpdateTypeAbbreviationInSignatureFile | ||
|
||
open FsAutoComplete.CodeFix.Types | ||
|
||
val title: string | ||
val fix: getParseResultsForFile: GetParseResultsForFile -> CodeFix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.