-
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.
POC: update value in signature file.
- Loading branch information
Showing
10 changed files
with
473 additions
and
342 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module FsAutoComplete.CodeFix.ToInterpolatedString | ||
|
||
open FsAutoComplete.CodeFix.Types | ||
open Ionide.LanguageServerProtocol.Types | ||
|
||
val title: string | ||
|
||
val fix: | ||
getParseResultsForFile: GetParseResultsForFile -> | ||
getLanguageVersion: GetLanguageVersion -> | ||
codeActionParams: CodeActionParams -> | ||
Async<Result<Fix list, string>> |
81 changes: 81 additions & 0 deletions
81
src/FsAutoComplete/CodeFixes/UpdateValueInSignatureFile.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,81 @@ | ||
module FsAutoComplete.CodeFix.UpdateValueInSignatureFile | ||
|
||
open FSharp.Compiler.Symbols | ||
open FSharp.Compiler.Syntax | ||
open FsToolkit.ErrorHandling | ||
open Ionide.LanguageServerProtocol.Types | ||
open FsAutoComplete.CodeFix.Types | ||
open FsAutoComplete | ||
open FsAutoComplete.LspHelpers | ||
|
||
let visitSynModuleSigDecl (name: string) (decl: SynModuleSigDecl) = | ||
match decl with | ||
| SynModuleSigDecl.Val(valSig = SynValSig(ident = SynIdent(ident = ident)); range = m) when ident.idText = name -> | ||
Some m | ||
| _ -> None | ||
|
||
let visitSynModuleOrNamespaceSig (name: string) (SynModuleOrNamespaceSig(decls = decls)) = | ||
decls |> List.tryPick (visitSynModuleSigDecl name) | ||
|
||
let visitParsedSigFileInput (name: string) (ParsedSigFileInput(contents = contents)) = | ||
contents |> List.tryPick (visitSynModuleOrNamespaceSig name) | ||
|
||
let visitTree (name: string) (tree: ParsedInput) = | ||
match tree with | ||
| ParsedInput.ImplFile _ -> None | ||
| ParsedInput.SigFile parsedSigFileInput -> visitParsedSigFileInput name parsedSigFileInput | ||
|
||
let title = "Update val in signature file" | ||
|
||
let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix = | ||
Run.ifDiagnosticByCode (Set.ofList [ "34" ]) (fun diagnostic codeActionParams -> | ||
asyncResult { | ||
let implFilePath = codeActionParams.TextDocument.GetFilePath() | ||
let sigFilePath = $"%s{implFilePath}i" | ||
|
||
let implFileName = Utils.normalizePath implFilePath | ||
let sigFileName = Utils.normalizePath sigFilePath | ||
|
||
let sigTextDocumentIdentifier: TextDocumentIdentifier = | ||
{ Uri = $"%s{codeActionParams.TextDocument.Uri}i" } | ||
|
||
let! (implParseAndCheckResults: ParseAndCheckResults, implLine: string, implSourceText: IFSACSourceText) = | ||
getParseResultsForFile implFileName (protocolPosToPos diagnostic.Range.Start) | ||
|
||
let! implBindingName = | ||
implSourceText.GetText(protocolRangeToRange implParseAndCheckResults.GetParseResults.FileName diagnostic.Range) | ||
|
||
let! (sigParseAndCheckResults: ParseAndCheckResults, _sigLine: string, _sigSourceText: IFSACSourceText) = | ||
getParseResultsForFile sigFileName (protocolPosToPos diagnostic.Range.Start) | ||
|
||
match visitTree implBindingName sigParseAndCheckResults.GetParseResults.ParseTree with | ||
| None -> return [] | ||
| Some mVal -> | ||
let endPos = protocolPosToPos diagnostic.Range.End | ||
|
||
let symbolUse = | ||
implParseAndCheckResults.GetCheckResults.GetSymbolUseAtLocation( | ||
endPos.Line, | ||
endPos.Column, | ||
implLine, | ||
[ implBindingName ] | ||
) | ||
|
||
match symbolUse with | ||
| None -> return [] | ||
| Some symbolUse -> | ||
match symbolUse.Symbol with | ||
| :? FSharpMemberOrFunctionOrValue as mfv -> | ||
match mfv.GetValSignatureText(symbolUse.DisplayContext, symbolUse.Range) with | ||
| None -> return [] | ||
| Some valText -> | ||
return | ||
[ { SourceDiagnostic = None | ||
Title = title | ||
File = sigTextDocumentIdentifier | ||
Edits = | ||
[| { Range = fcsRangeToLsp mVal | ||
NewText = valText } |] | ||
Kind = FixKind.Fix } ] | ||
| _ -> return [] | ||
}) |
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.UpdateValueInSignatureFile | ||
|
||
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
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.