Skip to content
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Allow `let!` and `use!` type annotations without requiring parentheses ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))
* Fix find all references for F# exceptions ([PR #18565](https://github.com/dotnet/fsharp/pull/18565))
* Shorthand lambda: fix completion for chained calls and analysis for unfinished expression ([PR #18560](https://github.com/dotnet/fsharp/pull/18560))
* Completion: fix previous namespace considered opened [PR #18609](https://github.com/dotnet/fsharp/pull/18609)

### Breaking Changes

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5428,6 +5428,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem

let envNS = LocateEnv kind.IsModule cenv.thisCcu env enclosingNamespacePath
let envNS = ImplicitlyOpenOwnNamespace cenv.tcSink g cenv.amap m enclosingNamespacePath envNS
CallEnvSink cenv.tcSink (m, envNS.NameEnv, env.eAccessRights)

let modTyNS = envNS.eModuleOrNamespaceTypeAccumulator.Value
let modTyRoot, modulNSs = BuildRootModuleType enclosingNamespacePath envNS.eCompPath modTyNS
Expand Down
10 changes: 9 additions & 1 deletion tests/FSharp.Compiler.Service.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ open System
open System.Diagnostics
open System.IO
open System.Collections.Generic
open System.Threading
open System.Threading.Tasks
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.EditorServices
open FSharp.Compiler.IO
open FSharp.Compiler.Symbols
open FSharp.Compiler.Syntax
Expand Down Expand Up @@ -352,6 +352,14 @@ let getCursorPosAndPrepareSource (source: string) : string * string * pos =
let lineText = lineText.Replace("{caret}", "")
source, lineText, Position.mkPos (line + 1) (column - 1)

let getPartialIdentifierAndPrepareSource source =
let source, lineText, pos = getCursorPosAndPrepareSource source
let _, column, _ = QuickParse.GetCompleteIdentifierIsland false lineText pos.Column |> Option.get
let pos = Position.mkPos pos.Line column
let plid = QuickParse.GetPartialLongNameEx(lineText, column - 1)
let names = plid.QualifyingIdents @ [plid.PartialIdent]
source, lineText, pos, plid, names

let getParseResults (source: string) =
parseSourceCode("Test.fsx", source)

Expand Down
32 changes: 29 additions & 3 deletions tests/FSharp.Compiler.Service.Tests/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ let getCompletionInfo source =
let getCompletionItemNames (completionInfo: DeclarationListInfo) =
completionInfo.Items |> Array.map (fun item -> item.NameInCode)

let assertHasItemWithNames names (completionInfo: DeclarationListInfo) =
let private assertItemsWithNames contains names (completionInfo: DeclarationListInfo) =
let itemNames = getCompletionItemNames completionInfo |> set

for name in names do
Assert.True(Set.contains name itemNames, $"{name} not found in {itemNames}")
Assert.True(Set.contains name itemNames = contains)

let assertHasItemWithNames names (completionInfo: DeclarationListInfo) =
assertItemsWithNames true names completionInfo

let assertHasNoItemsWithNames names (completionInfo: DeclarationListInfo) =
assertItemsWithNames false names completionInfo

[<Fact>]
let ``Expr - After record decl 01`` () =
Expand Down Expand Up @@ -353,4 +359,24 @@ module rec M =

let _: R{caret} = ()
"""
assertHasItemWithNames ["Rec1"; "Rec2"; "Rec3"] info
assertHasItemWithNames ["Rec1"; "Rec2"; "Rec3"] info

[<Fact>]
let ``Not in scope 01`` () =
let info =
getCompletionInfo """
namespace Ns1

type E =
| A = 1
| B = 2
| C = 3

namespace Ns2

module Module =
match Ns1.E.A with
| {caret}

"""
assertHasNoItemsWithNames ["E"] info
Original file line number Diff line number Diff line change
Expand Up @@ -4362,7 +4362,7 @@ let ``Test Project32 should be able to find impl symbols`` () =
checker.GetBackgroundCheckResultsForFileInProject(Project32.fileName1, Project32.options)
|> Async.RunImmediate

let implSymbolUseOpt = implBackgroundTypedParse1.GetSymbolUseAtLocation(3,5,"",["func"])
let implSymbolUseOpt = implBackgroundTypedParse1.GetSymbolUseAtLocation(3,5,"let func x = x + 1",["func"])
let implSymbol = implSymbolUseOpt.Value.Symbol

let usesOfImplSymbol =
Expand Down
Loading