Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Shims over completions and sig help
  • Loading branch information
TIHan committed May 8, 2019
commit 089d60cdf398a4cc019599f5cc260194e2342293
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.Options
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Completion

open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
Expand Down Expand Up @@ -52,7 +53,7 @@ type internal FSharpCompletionProvider
|> List.filter (fun (keyword, _) -> not (PrettyNaming.IsOperatorName keyword))
|> List.sortBy (fun (keyword, _) -> keyword)
|> List.mapi (fun n (keyword, description) ->
CommonCompletionItem.Create(keyword, null, CompletionItemRules.Default, Nullable Glyph.Keyword, sortText = sprintf "%06d" (1000000 + n))
FSharpCommonCompletionItem.Create(keyword, null, CompletionItemRules.Default, Nullable Glyph.Keyword, sortText = sprintf "%06d" (1000000 + n))
.AddProperty("description", description)
.AddProperty(IsKeywordPropName, ""))

Expand All @@ -77,7 +78,7 @@ type internal FSharpCompletionProvider
// * let xs = [1..10] <<---- Don't commit autocomplete! (same for arrays)
let noCommitChars = [|' '; '='; ','; '.'; '<'; '>'; '('; ')'; '!'; ':'; '['; ']'; '|'|].ToImmutableArray()

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

static let getRules showAfterCharIsTyped = if showAfterCharIsTyped then noCommitOnSpaceRules else CompletionItemRules.Default

Expand Down Expand Up @@ -156,7 +157,7 @@ type internal FSharpCompletionProvider
| _, idents -> Array.last idents

let completionItem =
CommonCompletionItem.Create(name, null, rules = getRules intellisenseOptions.ShowAfterCharIsTyped, glyph = Nullable (Microsoft.CodeAnalysis.ExternalAccess.FSharp.FSharpGlyphHelpersObsolete.Convert(glyph)), filterText = filterText)
FSharpCommonCompletionItem.Create(name, null, rules = getRules intellisenseOptions.ShowAfterCharIsTyped, glyph = Nullable glyph, filterText = filterText)
.AddProperty(FullNamePropName, declarationItem.FullName)

let completionItem =
Expand Down Expand Up @@ -202,7 +203,7 @@ type internal FSharpCompletionProvider
}

override this.ShouldTriggerCompletion(sourceText: SourceText, caretPosition: int, trigger: CompletionTrigger, _: OptionSet) =
use _logBlock = Logger.LogBlockMessage this.Name LogEditorFunctionId.Completion_ShouldTrigger
use _logBlock = Logger.LogBlock LogEditorFunctionId.Completion_ShouldTrigger

let getInfo() =
let documentId = workspace.GetDocumentIdInCurrentContext(sourceText.Container)
Expand Down
10 changes: 6 additions & 4 deletions vsintegration/src/FSharp.Editor/Completion/CompletionService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.Host
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Completion

open Microsoft.VisualStudio.Shell

Expand All @@ -26,10 +27,11 @@ type internal FSharpCompletionService
let builtInProviders =
ImmutableArray.Create<CompletionProvider>(
FSharpCompletionProvider(workspace, serviceProvider, checkerProvider, projectInfoManager, assemblyContentProvider),
HashDirectiveCompletionProvider(workspace, projectInfoManager,
[ Completion.Create("""\s*#load\s+(@?"*(?<literal>"[^"]*"?))""", [".fs"; ".fsx"], useIncludeDirectives = true)
Completion.Create("""\s*#r\s+(@?"*(?<literal>"[^"]*"?))""", [".dll"; ".exe"], useIncludeDirectives = true)
Completion.Create("""\s*#I\s+(@?"*(?<literal>"[^"]*"?))""", ["\x00"], useIncludeDirectives = false) ]))
FSharpCommonCompletionProvider.Create(
HashDirectiveCompletionProvider(workspace, projectInfoManager,
[ Completion.Create("""\s*#load\s+(@?"*(?<literal>"[^"]*"?))""", [".fs"; ".fsx"], useIncludeDirectives = true)
Completion.Create("""\s*#r\s+(@?"*(?<literal>"[^"]*"?))""", [".dll"; ".exe"], useIncludeDirectives = true)
Completion.Create("""\s*#I\s+(@?"*(?<literal>"[^"]*"?))""", ["\x00"], useIncludeDirectives = false) ])))

override this.Language = FSharpConstants.FSharpLanguageName
override this.GetBuiltInProviders() = builtInProviders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Completion
open System.Globalization
open FSharp.Compiler.SourceCodeServices

Expand Down Expand Up @@ -81,7 +82,7 @@ module internal CompletionUtils =
| _ -> false

let isStartingNewWord (sourceText, position) =
CommonCompletionUtilities.IsStartingNewWord(sourceText, position, (fun ch -> isIdentifierStartCharacter ch), (fun ch -> isIdentifierPartCharacter ch))
FSharpCommonCompletionUtilities.IsStartingNewWord(sourceText, position, (fun ch -> isIdentifierStartCharacter ch), (fun ch -> isIdentifierPartCharacter ch))

let shouldProvideCompletion (documentId: DocumentId, filePath: string, defines: string list, sourceText: SourceText, triggerPosition: int) : bool =
let textLines = sourceText.Lines
Expand Down
138 changes: 70 additions & 68 deletions vsintegration/src/FSharp.Editor/Completion/FileSystemCompletion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Completion

type internal Completion =
{ DirectiveRegex: Regex
Expand All @@ -23,7 +24,6 @@ type internal Completion =
UseIncludeDirectives = useIncludeDirectives }

type internal HashDirectiveCompletionProvider(workspace: Workspace, projectInfoManager: FSharpProjectOptionsManager, completions: Completion list) =
inherit CommonCompletionProvider()

let [<Literal>] NetworkPath = "\\\\"
let commitRules = ImmutableArray.Create(CharacterSetModificationRule.Create(CharacterSetModificationKind.Replace, '"', '\\', ',', '/'))
Expand Down Expand Up @@ -82,75 +82,77 @@ type internal HashDirectiveCompletionProvider(workspace: Workspace, projectInfoM
)
|> Seq.toList

override this.ProvideCompletionsAsync(context) =
asyncMaybe {
let document = context.Document
let position = context.Position
do! let extension = Path.GetExtension document.FilePath
Option.guard (extension = ".fsx" || extension = ".fsscript")

let! ct = liftAsync Async.CancellationToken
let! text = document.GetTextAsync(ct)
do! Option.guard (isInStringLiteral(text, position))
let line = text.Lines.GetLineFromPosition(position)
let lineText = text.ToString(TextSpan.FromBounds(line.Start, position))
interface IFSharpCommonCompletionProvider with

member this.ProvideCompletionsAsync(context) =
asyncMaybe {
let document = context.Document
let position = context.Position
do! let extension = Path.GetExtension document.FilePath
Option.guard (extension = ".fsx" || extension = ".fsscript")

let! ct = liftAsync Async.CancellationToken
let! text = document.GetTextAsync(ct)
do! Option.guard (isInStringLiteral(text, position))
let line = text.Lines.GetLineFromPosition(position)
let lineText = text.ToString(TextSpan.FromBounds(line.Start, position))

let! completion, quotedPathGroup =
completions |> List.tryPick (fun completion ->
match completion.DirectiveRegex.Match lineText with
| m when m.Success ->
let quotedPathGroup = m.Groups.["literal"]
let endsWithQuote = PathCompletionUtilities.EndsWithQuote(quotedPathGroup.Value)
if endsWithQuote && (position >= line.Start + m.Length) then
None
else
Some (completion, quotedPathGroup)
| _ -> None)

let snapshot = text.FindCorrespondingEditorTextSnapshot()
let! completion, quotedPathGroup =
completions |> List.tryPick (fun completion ->
match completion.DirectiveRegex.Match lineText with
| m when m.Success ->
let quotedPathGroup = m.Groups.["literal"]
let endsWithQuote = PathCompletionUtilities.EndsWithQuote(quotedPathGroup.Value)
if endsWithQuote && (position >= line.Start + m.Length) then
None
else
Some (completion, quotedPathGroup)
| _ -> None)

let snapshot = text.FindCorrespondingEditorTextSnapshot()

do! Option.guard (not (isNull snapshot))

let extraSearchPaths =
if completion.UseIncludeDirectives then
getIncludeDirectives (text, position)
else []

let defaultSearchPath = Path.GetDirectoryName document.FilePath
let searchPaths = defaultSearchPath :: extraSearchPaths

let helper =
FileSystemCompletionHelper(
Glyph.OpenFolder,
completion.AllowableExtensions |> List.tryPick getFileGlyph |> Option.defaultValue Glyph.None,
Seq.toImmutableArray searchPaths,
null,
completion.AllowableExtensions |> Seq.toImmutableArray,
rules)
do! Option.guard (not (isNull snapshot))

let extraSearchPaths =
if completion.UseIncludeDirectives then
getIncludeDirectives (text, position)
else []

let defaultSearchPath = Path.GetDirectoryName document.FilePath
let searchPaths = defaultSearchPath :: extraSearchPaths

let helper =
FSharpFileSystemCompletionHelper(
Glyph.OpenFolder,
completion.AllowableExtensions |> List.tryPick getFileGlyph |> Option.defaultValue Glyph.None,
Seq.toImmutableArray searchPaths,
null,
completion.AllowableExtensions |> Seq.toImmutableArray,
rules)

let pathThroughLastSlash = getPathThroughLastSlash(text, position, quotedPathGroup)
let! items = helper.GetItemsAsync(pathThroughLastSlash, ct) |> Async.AwaitTask |> liftAsync
context.AddItems(items)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask context.CancellationToken
let pathThroughLastSlash = getPathThroughLastSlash(text, position, quotedPathGroup)
let! items = helper.GetItemsAsync(pathThroughLastSlash, ct) |> Async.AwaitTask |> liftAsync
context.AddItems(items)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask context.CancellationToken

override __.IsInsertionTrigger(text, position, _) =
// Bring up completion when the user types a quote (i.e.: #r "), or if they type a slash
// path separator character, or if they type a comma (#r "foo,version...").
// Also, if they're starting a word. i.e. #r "c:\W
let ch = text.[position]
let isTriggerChar =
ch = '"' || ch = '\\' || ch = ',' || ch = '/' ||
CommonCompletionUtilities.IsStartingNewWord(text, position, (fun x -> Char.IsLetter x), (fun x -> Char.IsLetterOrDigit x))
isTriggerChar && isInStringLiteral(text, position)
member __.IsInsertionTrigger(text, position, _) =
// Bring up completion when the user types a quote (i.e.: #r "), or if they type a slash
// path separator character, or if they type a comma (#r "foo,version...").
// Also, if they're starting a word. i.e. #r "c:\W
let ch = text.[position]
let isTriggerChar =
ch = '"' || ch = '\\' || ch = ',' || ch = '/' ||
FSharpCommonCompletionUtilities.IsStartingNewWord(text, position, (fun x -> Char.IsLetter x), (fun x -> Char.IsLetterOrDigit x))
isTriggerChar && isInStringLiteral(text, position)

override __.GetTextChangeAsync(selectedItem, ch, cancellationToken) =
// When we commit "\\" when the user types \ we have to adjust for the fact that the
// controller will automatically append \ after we commit. Because of that, we don't
// want to actually commit "\\" as we'll end up with "\\\". So instead we just commit
// "\" and know that controller will append "\" and give us "\\".
if selectedItem.DisplayText = NetworkPath && ch = Nullable '\\' then
Task.FromResult(Nullable(TextChange(selectedItem.Span, "\\")))
else
base.GetTextChangeAsync(selectedItem, ch, cancellationToken)
member __.GetTextChangeAsync(baseGetTextChangeAsync, selectedItem, ch, cancellationToken) =
// When we commit "\\" when the user types \ we have to adjust for the fact that the
// controller will automatically append \ after we commit. Because of that, we don't
// want to actually commit "\\" as we'll end up with "\\\". So instead we just commit
// "\" and know that controller will append "\" and give us "\\".
if selectedItem.DisplayText = NetworkPath && ch = Nullable '\\' then
Task.FromResult(Nullable(TextChange(selectedItem.Span, "\\")))
else
baseGetTextChangeAsync.Invoke(selectedItem, ch, cancellationToken)
15 changes: 8 additions & 7 deletions vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open System.Collections.Generic
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.SignatureHelp
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.SignatureHelp

open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Shell
Expand All @@ -19,7 +20,7 @@ open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices

[<Shared>]
[<ExportSignatureHelpProvider("FSharpSignatureHelpProvider", FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpSignatureHelpProvider>)>]
type internal FSharpSignatureHelpProvider
[<ImportingConstructor>]
(
Expand Down Expand Up @@ -188,7 +189,7 @@ type internal FSharpSignatureHelpProvider
return Some items
}

interface ISignatureHelpProvider with
interface IFSharpSignatureHelpProvider with
member this.IsTriggerCharacter(c) = c ='(' || c = '<' || c = ','
member this.IsRetriggerCharacter(c) = c = ')' || c = '>' || c = '='

Expand All @@ -200,7 +201,7 @@ type internal FSharpSignatureHelpProvider
let! textVersion = document.GetTextVersionAsync(cancellationToken)

let triggerTypedChar =
if triggerInfo.TriggerCharacter.HasValue && triggerInfo.TriggerReason = SignatureHelpTriggerReason.TypeCharCommand then
if triggerInfo.TriggerCharacter.HasValue && triggerInfo.TriggerReason = FSharpSignatureHelpTriggerReason.TypeCharCommand then
Some triggerInfo.TriggerCharacter.Value
else None

Expand All @@ -211,10 +212,10 @@ type internal FSharpSignatureHelpProvider
|> Array.map (fun (hasParamArrayArg, doc, prefixParts, separatorParts, suffixParts, parameters, descriptionParts) ->
let parameters = parameters
|> Array.map (fun (paramName, isOptional, _typeText, paramDoc, displayParts) ->
SignatureHelpParameter(paramName,isOptional,documentationFactory=(fun _ -> paramDoc :> seq<_>),displayParts=displayParts))
SignatureHelpItem(isVariadic=hasParamArrayArg, documentationFactory=(fun _ -> doc :> seq<_>),prefixParts=prefixParts,separatorParts=separatorParts,suffixParts=suffixParts,parameters=parameters,descriptionParts=descriptionParts))
FSharpSignatureHelpParameter(paramName,isOptional,documentationFactory=(fun _ -> paramDoc :> seq<_>),displayParts=displayParts))
FSharpSignatureHelpItem(isVariadic=hasParamArrayArg, documentationFactory=(fun _ -> doc :> seq<_>),prefixParts=prefixParts,separatorParts=separatorParts,suffixParts=suffixParts,parameters=parameters,descriptionParts=descriptionParts))

return SignatureHelpItems(items,applicableSpan,argumentIndex,argumentCount,Option.toObj argumentName)
return FSharpSignatureHelpItems(items,applicableSpan,argumentIndex,argumentCount,Option.toObj argumentName)
with ex ->
Assert.Exception(ex)
return! None
Expand All @@ -234,4 +235,4 @@ open Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHelp.Pre
type internal FSharpSignatureHelpClassifierProvider [<ImportingConstructor>] (typeMap) =
interface IClassifierProvider with
override __.GetClassifier (buffer: ITextBuffer) =
buffer.Properties.GetOrCreateSingletonProperty(fun _ -> SignatureHelpClassifier(buffer, typeMap) :> _)
buffer.Properties.GetOrCreateSingletonProperty(fun _ -> FSharpSignatureHelpClassifier(buffer, typeMap) :> _)