Skip to content

Commit

Permalink
Merge pull request dotnet#3810 from Microsoft/master
Browse files Browse the repository at this point in the history
Merge F# code generation into vs2017-rtm
  • Loading branch information
brettfo authored Oct 24, 2017
2 parents af12d31 + ceb73ec commit a17c17d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions Commands/HelpContextService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open Microsoft.CodeAnalysis.Classification
open Microsoft.VisualStudio.FSharp.LanguageService
open Microsoft.VisualStudio.LanguageServices.Implementation.F1Help
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.SourceCodeServices

Expand Down
4 changes: 0 additions & 4 deletions Common/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ namespace Microsoft.VisualStudio.FSharp.Editor

open Microsoft.VisualStudio.Shell

[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("FSharp.ProjectSystem.FSharp, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("VisualFSharp.Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("VisualFSharp.Salsa, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]

[<assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\FSharp.Editor.dll")>]
[<assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\FSharp.UIResources.dll")>]
[<assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Newtonsoft.Json.dll")>]
Expand Down
30 changes: 22 additions & 8 deletions Completion/CompletionProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,23 @@ type internal FSharpCompletionProvider

let xmlMemberIndexService = serviceProvider.GetService(typeof<IVsXMLMemberIndexService>) :?> IVsXMLMemberIndexService
let documentationBuilder = XmlDocumentation.CreateDocumentationBuilder(xmlMemberIndexService, serviceProvider.DTE)

static let noCommitOnSpaceRules =
CompletionItemRules.Default.WithCommitCharacterRule(CharacterSetModificationRule.Create(CharacterSetModificationKind.Remove, ' ', '=', ',', '.', '<', '>', '(', ')', '!', ':'))
// These are important. They make sure we don't _commit_ autocompletion when people don't expect them to. Some examples:
//
// * type Foo() =
// member val a = 12 with get, <<---- Don't commit autocomplete!
//
// * type MyRecord = { name: <<---- Don't commit autocomplete!
//
// * type My< <<---- Don't commit autocomplete!
//
// * let myClassInstance = MyClass(Date= <<---- Don't commit autocomplete!
//
// * let xs = [1..10] <<---- Don't commit autocomplete! (same for arrays)
let noCommitChars = [|' '; '='; ','; '.'; '<'; '>'; '('; ')'; '!'; ':'; '['; ']'; '|'|].ToImmutableArray()

CompletionItemRules.Default.WithCommitCharacterRule(CharacterSetModificationRule.Create(CharacterSetModificationKind.Remove, noCommitChars))

static let getRules() = if Settings.IntelliSense.ShowAfterCharIsTyped then noCommitOnSpaceRules else CompletionItemRules.Default

Expand Down Expand Up @@ -100,14 +114,14 @@ type internal FSharpCompletionProvider
let caretLine = textLines.GetLineFromPosition(caretPosition)
let fcsCaretLineNumber = Line.fromZ caretLinePos.Line // Roslyn line numbers are zero-based, FSharp.Compiler.Service line numbers are 1-based
let caretLineColumn = caretLinePos.Character
let qualifyingNames, partialName = QuickParse.GetPartialLongNameEx(caretLine.ToString(), caretLineColumn - 1)
let partialName = QuickParse.GetPartialLongNameEx(caretLine.ToString(), caretLineColumn - 1)

let getAllSymbols() =
getAllSymbols() |> List.filter (fun entity -> entity.FullName.Contains "." && not (PrettyNaming.IsOperatorName entity.Symbol.DisplayName))
getAllSymbols()
|> List.filter (fun entity -> entity.FullName.Contains "." && not (PrettyNaming.IsOperatorName entity.Symbol.DisplayName))

let! declarations =
checkFileResults.GetDeclarationListInfo(Some(parseResults), fcsCaretLineNumber, caretLineColumn, caretLine.ToString(), qualifyingNames, partialName, getAllSymbols, userOpName=userOpName) |> liftAsync

let! declarations = checkFileResults.GetDeclarationListInfo(Some(parseResults), fcsCaretLineNumber, caretLine.ToString(),
partialName, getAllSymbols, userOpName=userOpName) |> liftAsync
let results = List<Completion.CompletionItem>()

let getKindPriority = function
Expand Down Expand Up @@ -186,7 +200,7 @@ type internal FSharpCompletionProvider
declarationItemsCache.Add(completionItem.DisplayText, declItem)
results.Add(completionItem))

if results.Count > 0 && not declarations.IsForType && not declarations.IsError && List.isEmpty qualifyingNames then
if results.Count > 0 && not declarations.IsForType && not declarations.IsError && List.isEmpty partialName.QualifyingIdents then
let lineStr = textLines.[caretLinePos.Line].ToString()
match UntypedParseImpl.TryGetCompletionContext(Pos.fromZ caretLinePos.Line caretLinePos.Character, Some parseResults, lineStr) with
| None -> results.AddRange(keywordCompletionItems)
Expand Down
2 changes: 1 addition & 1 deletion Debugging/LanguageDebugInfoService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open Microsoft.CodeAnalysis.Editor.Implementation.Debugging
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text

open Microsoft.VisualStudio.FSharp.LanguageService
open Microsoft.FSharp.Compiler

[<Shared>]
[<ExportLanguageService(typeof<ILanguageDebugInfoService>, FSharpConstants.FSharpLanguageName)>]
Expand Down
6 changes: 3 additions & 3 deletions Diagnostics/SimplifyNameDiagnosticAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ type internal SimplifyNameDiagnosticAnalyzer() =
|> Array.Parallel.map (fun symbolUse ->
let lineStr = sourceText.Lines.[Line.toZ symbolUse.RangeAlternate.StartLine].ToString()
// for `System.DateTime.Now` it returns ([|"System"; "DateTime"|], "Now")
let plid, name = QuickParse.GetPartialLongNameEx(lineStr, symbolUse.RangeAlternate.EndColumn - 1)
let partialName = QuickParse.GetPartialLongNameEx(lineStr, symbolUse.RangeAlternate.EndColumn - 1)
// `symbolUse.RangeAlternate.Start` does not point to the start of plid, it points to start of `name`,
// so we have to calculate plid's start ourselves.
let plidStartCol = symbolUse.RangeAlternate.EndColumn - name.Length - (getPlidLength plid)
symbolUse, plid, plidStartCol, name)
let plidStartCol = symbolUse.RangeAlternate.EndColumn - partialName.PartialIdent.Length - (getPlidLength partialName.QualifyingIdents)
symbolUse, partialName.QualifyingIdents, plidStartCol, partialName.PartialIdent)
|> Array.filter (fun (_, plid, _, name) -> name <> "" && not (List.isEmpty plid))
|> Array.groupBy (fun (symbolUse, _, plidStartCol, _) -> symbolUse.RangeAlternate.StartLine, plidStartCol)
|> Array.map (fun (_, xs) -> xs |> Array.maxBy (fun (symbolUse, _, _, _) -> symbolUse.RangeAlternate.EndColumn))
Expand Down
5 changes: 5 additions & 0 deletions FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<IncludePkgdefInVSIXContainer>true</IncludePkgdefInVSIXContainer>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="FSharp.ProjectSystem.FSharp" />
<InternalsVisibleTo Include="VisualFSharp.Unittests" />
<InternalsVisibleTo Include="VisualFSharp.Salsa" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FSharp.Editor.resx">
<GenerateSource>true</GenerateSource>
Expand Down
4 changes: 2 additions & 2 deletions LanguageService/Tokenizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ module internal Tokenizer =
| _ -> false)
|> Option.orElseWith (fun _ -> tokensUnderCursor |> List.tryFind (fun { DraftToken.Kind = k } -> k = LexerSymbolKind.Operator))
|> Option.map (fun token ->
let plid, _ = QuickParse.GetPartialLongNameEx(lineStr, token.RightColumn)
let partialName = QuickParse.GetPartialLongNameEx(lineStr, token.RightColumn)
let identStr = lineStr.Substring(token.Token.LeftColumn, token.Token.FullMatchedLength)
{ Kind = token.Kind
Ident =
Expand All @@ -541,7 +541,7 @@ module internal Tokenizer =
fileName
(Range.mkPos (linePos.Line + 1) token.Token.LeftColumn)
(Range.mkPos (linePos.Line + 1) (token.RightColumn + 1)))
FullIsland = plid @ [identStr] })
FullIsland = partialName.QualifyingIdents @ [identStr] })

let private getCachedSourceLineData(documentKey: DocumentId, sourceText: SourceText, position: int, fileName: string, defines: string list) =
let textLine = sourceText.Lines.GetLineFromPosition(position)
Expand Down
2 changes: 1 addition & 1 deletion Options/EditorOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module DefaultTuning =
let UnusedDeclarationsAnalyzerInitialDelay = 0 (* 1000 *) (* milliseconds *)
let UnusedOpensAnalyzerInitialDelay = 0 (* 2000 *) (* milliseconds *)
let SimplifyNameInitialDelay = 2000 (* milliseconds *)
let SimplifyNameEachItemDelay = 5 (* milliseconds *)
let SimplifyNameEachItemDelay = 0 (* milliseconds *)

// CLIMutable to make the record work also as a view model
[<CLIMutable>]
Expand Down

0 comments on commit a17c17d

Please sign in to comment.