Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2f3b4d

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
PrefixUnusedValueWithUnderscore Code Fix does not trigger on operators and backticked identifiers (dotnet#2424)
1 parent09a8c60 commitb2f3b4d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

‎vsintegration/src/FSharp.Editor/CodeFix/PrefixUnusedValueWithUnderscore.fs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ open Microsoft.CodeAnalysis.Text
1212
openMicrosoft.CodeAnalysis.CodeFixes
1313
openMicrosoft.CodeAnalysis.CodeActions
1414

15+
openMicrosoft.FSharp.Compiler
16+
1517
[<ExportCodeFixProvider(FSharpCommonConstants.FSharpLanguageName, Name="PrefixUnusedValueWithUnderscore"); Shared>]
1618
typeinternalFSharpPrefixUnusedValueWithUnderscoreCodeFixProvider()=
1719
inherit CodeFixProvider()
@@ -30,8 +32,14 @@ type internal FSharpPrefixUnusedValueWithUnderscoreCodeFixProvider() =
3032
override__.FixableDiagnosticIds= fixableDiagnosticIds.ToImmutableArray()
3133

3234
override__.RegisterCodeFixesAsync context:Task=
33-
async{
34-
letdiagnostics=(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds|> List.contains x.Id)).ToImmutableArray()
35-
context.RegisterCodeFix(createCodeFix(SR.PrefixValueNameWithUnderscore.Value, context, TextChange(TextSpan(context.Span.Start,0),"_")), diagnostics)
36-
context.RegisterCodeFix(createCodeFix(SR.RenameValueToUnderscore.Value, context, TextChange(context.Span,"_")), diagnostics)
35+
async{
36+
let!sourceText= context.Document.GetTextAsync()
37+
letident= sourceText.ToString(context.Span)
38+
// Prefixing operators and backticked identifiers does not make sense.
39+
// We have to use the additional check for backtickes because `IsOperatorOrBacktickedName` operates on display names
40+
// where backtickes are replaced with parens.
41+
ifnot(PrettyNaming.IsOperatorOrBacktickedName ident)&&not(ident.StartsWith"``")then
42+
letdiagnostics=(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds|> List.contains x.Id)).ToImmutableArray()
43+
context.RegisterCodeFix(createCodeFix(SR.PrefixValueNameWithUnderscore.Value, context, TextChange(TextSpan(context.Span.Start,0),"_")), diagnostics)
44+
context.RegisterCodeFix(createCodeFix(SR.RenameValueToUnderscore.Value, context, TextChange(context.Span,"_")), diagnostics)
3745
}|> CommonRoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

‎vsintegration/src/FSharp.Editor/DocumentHighlights/DocumentHighlightsService.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open Microsoft.CodeAnalysis.Host.Mef
1515
openMicrosoft.CodeAnalysis.Text
1616

1717
openMicrosoft.FSharp.Compiler.SourceCodeServices
18+
openMicrosoft.FSharp.Compiler.Range
1819

1920
typeinternalFSharpHighlightSpan=
2021
{ IsDefinition:bool
@@ -56,7 +57,7 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
5657
asyncMaybe{
5758
lettextLine= sourceText.Lines.GetLineFromPosition(position)
5859
lettextLinePos= sourceText.Lines.GetLinePosition(position)
59-
letfcsTextLineNumber= textLinePos.Line+1
60+
letfcsTextLineNumber=Line.fromZtextLinePos.Line
6061
let!symbol= CommonHelpers.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy)
6162
let!_,_,checkFileResults= checker.ParseAndCheckDocument(filePath, textVersionHash, sourceText.ToString(), options, allowStaleResults=true)
6263
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp