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

Commit798345d

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Add validation to Inline Rename (dotnet#2426)
* add validation to InlineRenameService* address review
1 parent71a3609 commit798345d

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

‎VisualFSharp.sln‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion =15.0.26020.0
4+
VisualStudioVersion =15.0.26206.0
55
MinimumVisualStudioVersion =10.0.40219.1
66
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") ="FSharp.Compiler","src\fsharp\FSharp.Compiler\FSharp.Compiler.fsproj","{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}"
77
EndProject
@@ -122,11 +122,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextFile", "vsintegration\I
122122
EndProject
123123
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") ="XMLFile","vsintegration\ItemTemplates\XMLFile\XMLFile.csproj","{1FB1DD07-06AA-45B4-B5AC-20FF5BEE98B6}"
124124
EndProject
125-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") ="Solution Items","Solution Items","{A83A9A70-8C33-4253-BF6F-3AADB509F21C}"
126-
ProjectSection(SolutionItems) =preProject
127-
Performance1.psess=Performance1.psess
128-
EndProjectSection
129-
EndProject
130125
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") ="Vsix","Vsix","{141F6C23-E1B1-4D89-9F10-F0B8AD58E71F}"
131126
EndProject
132127
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") ="VisualFSharpFull","vsintegration\Vsix\VisualFSharpFull\VisualFSharpFull.csproj","{59ADCE46-9740-4079-834D-9A03A3494EBC}"

‎vsintegration/src/FSharp.Editor/Common/CommonHelpers.fs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,56 @@ module internal CommonHelpers =
341341
|-1|0-> span
342342
| index-> TextSpan(span.Start+ index+1, text.Length- index-1)
343343

344+
letisValidNameForSymbol(lexerSymbolKind:LexerSymbolKind,symbol:FSharpSymbol,name:string):bool=
345+
letdoubleBackTickDelimiter="``"
346+
347+
letisDoubleBacktickIdent(s:string)=
348+
letdoubledDelimiter=2* doubleBackTickDelimiter.Length
349+
if s.StartsWith(doubleBackTickDelimiter)&& s.EndsWith(doubleBackTickDelimiter)&& s.Length> doubledDelimiterthen
350+
letinner= s.Substring(doubleBackTickDelimiter.Length, s.Length- doubledDelimiter)
351+
not(inner.Contains(doubleBackTickDelimiter))
352+
elsefalse
353+
354+
letisIdentifier(ident:string)=
355+
if isDoubleBacktickIdent identthen
356+
true
357+
else
358+
ident
359+
|> Seq.mapi(fun i c-> i, c)
360+
|> Seq.forall(fun(i,c)->
361+
if i=0then PrettyNaming.IsIdentifierFirstCharacter c
362+
else PrettyNaming.IsIdentifierPartCharacter c)
363+
364+
letisFixableIdentifier(s:string)=
365+
not(String.IsNullOrEmpty s)&& Lexhelp.Keywords.NormalizeIdentifierBackticks s|> isIdentifier
366+
367+
letforbiddenChars=[|'.';'+';'$';'&';'[';']';'/';'\\';'*';'\''|]
368+
369+
letisTypeNameIdent(s:string)=
370+
not(String.IsNullOrEmpty s)&& s.IndexOfAny forbiddenChars=-1&& isFixableIdentifier s
371+
372+
letisUnionCaseIdent(s:string)=
373+
isTypeNameIdent s&& Char.IsUpper(s.Replace(doubleBackTickDelimiter,"").[0])
374+
375+
letisTypeParameter(prefix:char)(s:string)=
376+
s.Length>=2&& s.[0]= prefix&& isIdentifier s.[1..]
377+
378+
letisGenericTypeParameter= isTypeParameter'''
379+
letisStaticallyResolvedTypeParameter= isTypeParameter'^'
380+
381+
match lexerSymbolKind, symbolwith
382+
|_,:? FSharpUnionCase-> isUnionCaseIdent name
383+
|_,:? FSharpActivePatternCase->
384+
// Different from union cases, active patterns don't accept double-backtick identifiers
385+
isFixableIdentifier name&&not(String.IsNullOrEmpty name)&& Char.IsUpper(name.[0])
386+
| LexerSymbolKind.Operator,_-> PrettyNaming.IsOperatorName name
387+
| LexerSymbolKind.GenericTypeParameter,_-> isGenericTypeParameter name
388+
| LexerSymbolKind.StaticallyResolvedTypeParameter,_-> isStaticallyResolvedTypeParameter name
389+
|(LexerSymbolKind.Ident| LexerSymbolKind.Other),_->
390+
match symbolwith
391+
|:? FSharpEntityas ewhen e.IsClass|| e.IsFSharpRecord|| e.IsFSharpUnion|| e.IsValueType|| e.IsFSharpModule|| e.IsInterface-> isTypeNameIdent name
392+
|_-> isFixableIdentifier name
393+
344394
[<RequireQualifiedAccess; NoComparison>]
345395
typeinternalSymbolDeclarationLocation=
346396
| CurrentDocument

‎vsintegration/src/FSharp.Editor/InlineRename/InlineRenameService.fs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type internal DocumentLocations =
4343
{ Document:Document
4444
Locations:InlineRenameLocation[]}
4545

46-
typeinternalInlineRenameLocationSet(locationsByDocument: DocumentLocations[],originalSolution: Solution)=
46+
typeinternalInlineRenameLocationSet(locationsByDocument: DocumentLocations[],originalSolution: Solution,symbolKind: LexerSymbolKind,symbol: FSharpSymbol)=
4747
interface IInlineRenameLocationSetwith
4848
member__.Locations:IList<InlineRenameLocation>=
4949
upcast[|for docin locationsByDocumentdoyield! doc.Locations|].ToList()
@@ -66,7 +66,7 @@ type internal InlineRenameLocationSet(locationsByDocument: DocumentLocations [],
6666
return
6767
{new IInlineRenameReplacementInfowith
6868
member__.NewSolution= newSolution
69-
member__.ReplacementTextValid=true
69+
member__.ReplacementTextValid=CommonHelpers.isValidNameForSymbol(symbolKind, symbol, replacementText)
7070
member__.DocumentIds= locationsByDocument|> Seq.map(fun doc-> doc.Document.Id)
7171
member__.GetReplacements(documentId)= Seq.empty}
7272
}
@@ -78,6 +78,7 @@ type internal InlineRenameInfo
7878
projectInfoManager: ProjectInfoManager,
7979
document: Document,
8080
sourceText: SourceText,
81+
lexerSymbol: LexerSymbol,
8182
symbolUse: FSharpSymbolUse,
8283
declLoc: SymbolDeclarationLocation,
8384
checkFileResults: FSharpCheckFileResults
@@ -130,7 +131,7 @@ type internal InlineRenameInfo
130131
return{ Document= document; Locations= locations}
131132
})
132133
|> Async.Parallel
133-
return InlineRenameLocationSet(locationsByDocument, document.Project.Solution):> IInlineRenameLocationSet
134+
return InlineRenameLocationSet(locationsByDocument, document.Project.Solution, lexerSymbol.Kind, symbolUse.Symbol):> IInlineRenameLocationSet
134135
}|> CommonRoslynHelpers.StartAsyncAsTask(cancellationToken)
135136

136137
member__.TryOnBeforeGlobalSymbolRenamed(_workspace,_changedDocumentIDs,_replacementText)=true
@@ -150,12 +151,12 @@ type internal InlineRenameService
150151
asyncMaybe{
151152
lettextLine= sourceText.Lines.GetLineFromPosition(position)
152153
lettextLinePos= sourceText.Lines.GetLinePosition(position)
153-
letfcsTextLineNumber=textLinePos.Line+1// Roslyn line numbers are zero-based, FSharp.Compiler.Service line numbers are 1-based
154+
letfcsTextLineNumber= Line.fromZ textLinePos.Line
154155
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy)
155156
let!_,_,checkFileResults= checker.ParseAndCheckDocument(document, options, allowStaleResults=true)
156157
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.Text.ToString(), symbol.FullIsland)
157158
let!declLoc= symbolUse.GetDeclarationLocation(document)
158-
return InlineRenameInfo(checker, projectInfoManager, document, sourceText, symbolUse, declLoc, checkFileResults):> IInlineRenameInfo
159+
return InlineRenameInfo(checker, projectInfoManager, document, sourceText,symbol,symbolUse, declLoc, checkFileResults):> IInlineRenameInfo
159160
}
160161

161162
interface IEditorInlineRenameServicewith

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp