Skip to content
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

Merge master to release/dev16.8 #9944

Merged
merged 3 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1534,5 +1534,6 @@ forFormatInvalidForInterpolated4,"Interpolated strings used as type IFormattable
3379,parsEofInInterpolatedString,"Incomplete interpolated string begun at or before here"
3380,parsEofInInterpolatedVerbatimString,"Incomplete interpolated verbatim string begun at or before here"
3381,parsEofInInterpolatedTripleQuoteString,"Incomplete interpolated triple-quote string begun at or before here"
3382,lexRBraceInInterpolatedString,"A '}}' character must be escaped (by doubling) in an interpolated string."
3382,parsEmptyFillInInterpolatedString,"Invalid interpolated string. This interpolated string expression fill is empty, an expression was expected."
3383,lexRBraceInInterpolatedString,"A '}}' character must be escaped (by doubling) in an interpolated string."
#3501 "This construct is not supported by your version of the F# compiler" CompilerMessage(ExperimentalAttributeMessages.NotSupportedYet, 3501, IsError=true)
14 changes: 14 additions & 0 deletions src/fsharp/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -5507,6 +5507,13 @@ interpolatedStringParts:
| INTERP_STRING_PART interpolatedStringFill interpolatedStringParts
{ SynInterpolatedStringPart.String (fst $1, rhs parseState 1) :: SynInterpolatedStringPart.FillExpr $2 :: $3 }

| INTERP_STRING_PART interpolatedStringParts
{
let rbrace = parseState.InputEndPosition 1
let lbrace = parseState.InputStartPosition 2
reportParseErrorAt (mkSynRange rbrace lbrace) (FSComp.SR.parsEmptyFillInInterpolatedString())
SynInterpolatedStringPart.String (fst $1, rhs parseState 1) :: $2 }

/* INTERP_STRING_BEGIN_END */
/* INTERP_STRING_BEGIN_PART int32 INTERP_STRING_END */
/* INTERP_STRING_BEGIN_PART int32 INTERP_STRING_PART int32 INTERP_STRING_END */
Expand All @@ -5516,6 +5523,13 @@ interpolatedString:

| INTERP_STRING_BEGIN_END
{ [ SynInterpolatedStringPart.String (fst $1, rhs parseState 1) ] }

| INTERP_STRING_BEGIN_PART interpolatedStringParts
{
let rbrace = parseState.InputEndPosition 1
let lbrace = parseState.InputStartPosition 2
reportParseErrorAt (mkSynRange rbrace lbrace) (FSComp.SR.parsEmptyFillInInterpolatedString())
SynInterpolatedStringPart.String (fst $1, rhs parseState 1) :: $2 }

opt_HIGH_PRECEDENCE_APP:
| HIGH_PRECEDENCE_BRACK_APP { }
Expand Down
41 changes: 26 additions & 15 deletions src/fsharp/service/SemanticClassification.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SemanticClassificationType =
| Property
| MutableVar
| Module
| NameSpace
| Namespace
| Printf
| ComputationExpression
| IntrinsicFunction
Expand All @@ -55,6 +55,7 @@ type SemanticClassificationType =
| LocalValue
| Type
| TypeDef
| Plaintext

[<AutoOpen>]
module TcResolutionsExtensions =
Expand Down Expand Up @@ -164,8 +165,10 @@ module TcResolutionsExtensions =
add m SemanticClassificationType.IntrinsicFunction

| (Item.Value vref), _, _, _, _, m when isFunction g vref.Type ->
if valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then
()
if isDiscard vref.DisplayName then
add m SemanticClassificationType.Plaintext
elif valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then
add m SemanticClassificationType.Operator
elif vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then
add m SemanticClassificationType.Property
elif vref.IsMember then
Expand Down Expand Up @@ -213,21 +216,29 @@ module TcResolutionsExtensions =
add m SemanticClassificationType.Property

| Item.CtorGroup (_, minfos), _, _, _, _, m ->
if minfos |> List.forall (fun minfo -> isDisposableTy minfo.ApparentEnclosingType) then
add m SemanticClassificationType.DisposableType
elif minfos |> List.forall (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then
add m SemanticClassificationType.ConstructorForValueType
else
match minfos with
| [] ->
add m SemanticClassificationType.ConstructorForReferenceType
| _ ->
if minfos |> List.forall (fun minfo -> isDisposableTy minfo.ApparentEnclosingType) then
add m SemanticClassificationType.DisposableType
elif minfos |> List.forall (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then
add m SemanticClassificationType.ConstructorForValueType
else
add m SemanticClassificationType.ConstructorForReferenceType

| (Item.DelegateCtor _ | Item.FakeInterfaceCtor _), _, _, _, _, m ->
add m SemanticClassificationType.ConstructorForReferenceType

| Item.MethodGroup (_, minfos, _), _, _, _, _, m ->
if minfos |> List.forall (fun minfo -> minfo.IsExtensionMember || minfo.IsCSharpStyleExtensionMember) then
add m SemanticClassificationType.ExtensionMethod
else
match minfos with
| [] ->
add m SemanticClassificationType.Method
| _ ->
if minfos |> List.forall (fun minfo -> minfo.IsExtensionMember || minfo.IsCSharpStyleExtensionMember) then
add m SemanticClassificationType.ExtensionMethod
else
add m SemanticClassificationType.Method

// Special case measures for struct types
| Item.Types(_, TType_app(tyconRef, TType_measure _ :: _) :: _), LegitTypeOccurence, _, _, _, m when isStructTyconRef tyconRef ->
Expand Down Expand Up @@ -295,7 +306,7 @@ module TcResolutionsExtensions =

| Item.ModuleOrNamespaces (modref :: _), LegitTypeOccurence, _, _, _, m ->
if modref.IsNamespace then
add m SemanticClassificationType.NameSpace
add m SemanticClassificationType.Namespace
else
add m SemanticClassificationType.Module

Expand Down Expand Up @@ -331,7 +342,7 @@ module TcResolutionsExtensions =
elif tcref.IsModule then
add m SemanticClassificationType.Module
elif tcref.IsNamespace then
add m SemanticClassificationType.NameSpace
add m SemanticClassificationType.Namespace
elif tcref.IsUnionTycon || tcref.IsRecordTycon then
if isStructTyconRef tcref then
add m SemanticClassificationType.ValueType
Expand All @@ -351,8 +362,8 @@ module TcResolutionsExtensions =
else
add m SemanticClassificationType.ReferenceType

| _ ->
())
| _, _, _, _, _, m ->
add m SemanticClassificationType.Plaintext)
results.AddRange(formatSpecifierLocations |> Array.map (fun (m, _) -> struct(m, SemanticClassificationType.Printf)))
results.ToArray()
)
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/service/SemanticClassification.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SemanticClassificationType =
| Property
| MutableVar
| Module
| NameSpace
| Namespace
| Printf
| ComputationExpression
| IntrinsicFunction
Expand All @@ -47,6 +47,7 @@ type SemanticClassificationType =
| LocalValue
| Type
| TypeDef
| Plaintext

/// Extension methods for the TcResolutions type.
[<AutoOpen>]
Expand Down
21 changes: 15 additions & 6 deletions tests/fsharp/Compiler/Language/StringInterpolation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,17 @@ let xd = $"%A{}" // empty expression
"""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 10, (2, 15, 2, 17),
"Unexpected interpolated string (final part) in binding")
[|(FSharpErrorSeverity.Error, 3382, (2, 15, 2, 15),
"Invalid interpolated string. This interpolated string expression fill is empty, an expression was expected.")
|]

let code = """
let xd = $"%A{ }" // empty expression
"""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 3382, (2, 15, 2, 17),
"Invalid interpolated string. This interpolated string expression fill is empty, an expression was expected.")
|]

[<Test>]
Expand Down Expand Up @@ -818,29 +827,29 @@ let TripleInterpolatedInVerbatimInterpolated = $\"123{456}789{$\"\"\"012\"\"\"}3
let code = "let x1 = $\"}\""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 3382, (1, 10, 1, 14),
[|(FSharpErrorSeverity.Error, 3383, (1, 10, 1, 14),
"A '}' character must be escaped (by doubling) in an interpolated string.")|]

[<Test>]
let ``String interpolation extra right brace verbatim`` () =
let code = "let x1 = @$\"}\""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 3382, (1, 10, 1, 15),
[|(FSharpErrorSeverity.Error, 3383, (1, 10, 1, 15),
"A '}' character must be escaped (by doubling) in an interpolated string.")|]

[<Test>]
let ``String interpolation extra right brace triple`` () =
let code = "let x1 = $\"\"\"}\"\"\""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 3382, (1, 10, 1, 18),
[|(FSharpErrorSeverity.Error, 3383, (1, 10, 1, 18),
"A '}' character must be escaped (by doubling) in an interpolated string.")|]

[<Test>]
let ``String interpolation extra right brace single quote with hole`` () =
let code = "let x1 = $\"{0}}\""
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |]
code
[|(FSharpErrorSeverity.Error, 3382, (1, 14, 1, 17),
[|(FSharpErrorSeverity.Error, 3383, (1, 14, 1, 17),
"A '}' character must be escaped (by doubling) in an interpolated string.")|]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module internal FSharpClassificationTypes =
| SemanticClassificationType.MutableVar -> MutableVar
| SemanticClassificationType.DisposableValue -> DisposableValue
| SemanticClassificationType.DisposableType -> DisposableType
| SemanticClassificationType.NameSpace -> ClassificationTypeNames.NamespaceName
| SemanticClassificationType.Namespace -> ClassificationTypeNames.NamespaceName
| SemanticClassificationType.Printf -> Printf
| SemanticClassificationType.Exception
| SemanticClassificationType.Module
Expand Down Expand Up @@ -63,6 +63,7 @@ module internal FSharpClassificationTypes =
| SemanticClassificationType.Delegate -> ClassificationTypeNames.DelegateName
| SemanticClassificationType.Value -> ClassificationTypeNames.Identifier
| SemanticClassificationType.LocalValue -> ClassificationTypeNames.LocalName
| SemanticClassificationType.Plaintext -> ClassificationTypeNames.Text

module internal ClassificationDefinitions =

Expand Down
29 changes: 19 additions & 10 deletions vsintegration/src/FSharp.Editor/LanguageService/SymbolHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ module internal SymbolHelpers =
let getSymbolUsesInSolution (symbol: FSharpSymbol, declLoc: SymbolDeclarationLocation, checkFileResults: FSharpCheckFileResults,
projectInfoManager: FSharpProjectOptionsManager, checker: FSharpChecker, solution: Solution, userOpName) =
async {
let toDict (symbolUses: range seq) =
(symbolUses
|> Seq.collect (fun symbolUse ->
solution.GetDocumentIdsWithFilePath(symbolUse.FileName) |> Seq.map (fun id -> id, symbolUse))
|> Seq.groupBy fst
).ToImmutableDictionary(
let toDict (symbolUseRanges: range seq) =
let groups =
symbolUseRanges
|> Seq.collect (fun symbolUse ->
solution.GetDocumentIdsWithFilePath(symbolUse.FileName) |> Seq.map (fun id -> id, symbolUse))
|> Seq.groupBy fst
groups.ToImmutableDictionary(
(fun (id, _) -> id),
fun (_, xs) -> xs |> Seq.map snd |> Seq.toArray)

Expand All @@ -77,7 +78,7 @@ module internal SymbolHelpers =
let! symbolUses = checkFileResults.GetUsesOfSymbolInFile(symbol)
return toDict (symbolUses |> Seq.map (fun symbolUse -> symbolUse.RangeAlternate))
| SymbolDeclarationLocation.Projects (projects, isInternalToProject) ->
let symbolUses = ResizeArray()
let symbolUseRanges = ImmutableArray.CreateBuilder()

let projects =
if isInternalToProject then projects
Expand All @@ -86,10 +87,18 @@ module internal SymbolHelpers =
yield project
yield! project.GetDependentProjects() ]
|> List.distinctBy (fun x -> x.Id)

let onFound =
fun _ _ symbolUseRange ->
async { symbolUseRanges.Add symbolUseRange }

let! _ = getSymbolUsesInProjects (symbol, projectInfoManager, checker, projects, onFound, userOpName)

let! _ = getSymbolUsesInProjects (symbol, projectInfoManager, checker, projects, (fun _ _ symbolUse -> async { symbolUses.Add symbolUse }), userOpName)

return toDict symbolUses }
// Distinct these down because each TFM will produce a new 'project'.
// Unless guarded by a #if define, symbols with the same range will be added N times
let symbolUseRanges = symbolUseRanges.ToArray() |> Array.distinct
return toDict symbolUseRanges
}

type OriginalText = string

Expand Down