@@ -338,115 +338,51 @@ module internal TipFormatter =
338
338
type internal TypedParseResult ( info : TypeCheckResults , untyped : UntypedParseInfo ) =
339
339
let token = Parser.tagOfToken( Parser.token.IDENT( " " ))
340
340
341
- let preCrack ( offset , doc : Mono.TextEditor.TextDocument ) =
341
+ let getLineInfoFromOffset ( offset , doc : Mono.TextEditor.TextDocument ) =
342
342
let loc = doc.OffsetToLocation( offset)
343
343
let line , col = max ( loc.Line - 1 ) 0 , loc.Column-1
344
344
let currentLine = doc.Lines |> Seq.nth line
345
345
let lineStr = doc.Text.Substring( currentLine.Offset, currentLine.EndOffset - currentLine.Offset)
346
- ( loc, line, col, currentLine, lineStr)
347
-
348
- // Parsing - find the identifier around the current location
349
- // (we look for full identifier in the backward direction, but only
350
- // for a short identifier forward - this means that when you hover
351
- // 'B' in 'A.B.C', you will get intellisense for 'A.B' module)
352
- let crackSymbolText ( offset : int , doc : Mono.TextEditor.TextDocument ) =
353
-
354
- let loc , line , col , currentLine , lineStr = preCrack ( offset, doc)
355
-
356
- let lookBack = Parsing.createBackStringReader lineStr ( col-1 )
357
- let lookForw = Parsing.createForwardStringReader lineStr col
358
-
359
- let backIdentOpt = Parsing.tryGetFirst Parsing.parseBackLongIdent lookBack
360
- match backIdentOpt with
361
- | None -> None
362
- | Some backIdent ->
363
- let nextIdentOpt = Parsing.tryGetFirst Parsing.parseIdent lookForw
364
- match nextIdentOpt with
365
- | None -> None
366
- | Some nextIdent ->
367
-
368
- let currentIdent , identIsland =
369
- match List.rev backIdent with
370
- | last:: prev ->
371
- let current = last + nextIdent
372
- current, current:: prev |> List.rev
373
- | [] -> " " , []
374
-
375
- Debug.WriteLine( sprintf " Result: Crack symbol text at %d :%d (offset %d - %d )\n Identifier: %A (Current: %s ) \n Line string: %s "
376
- line col currentLine.Offset currentLine.EndOffset identIsland currentIdent lineStr)
377
-
378
- match identIsland with
379
- | [] | [ " " ] -> None
380
- | _ -> Some ( line, col + nextIdent.Length, lineStr, identIsland, currentIdent, token)
381
-
382
- /// Crack the info prior to a '(' or ',' once the method tip trigger '(' shows
383
- let crackSymbolTextAtGetMethodsTrigger ( offset : int , doc : Mono.TextEditor.TextDocument ) =
384
-
385
- let loc , line , col , currentLine , lineStr = preCrack ( offset, doc)
386
- let lookBack = Parsing.createBackStringReader lineStr col
387
- let backIdentOpt = Parsing.tryGetFirst Parsing.parseBackTriggerThenLongIdent lookBack
388
- match backIdentOpt with
389
- | None -> None
390
- | Some backIdent ->
391
-
392
- let currentIdent , identIsland =
393
- match List.rev backIdent with
394
- | last:: prev -> last, ( last:: prev |> List.rev)
395
- | [] -> " " , []
396
-
397
- match identIsland with
398
- | [] | [ " " ] -> None
399
- | _ -> Some ( line, col, lineStr, identIsland, currentIdent, token)
400
-
346
+ ( line, col, lineStr)
401
347
402
348
/// Get declarations at the current location in the specified document
403
349
/// (used to implement dot-completion in 'FSharpTextEditorCompletion.fs')
404
350
member x.GetDeclarations ( doc : Document , context : CodeCompletion.CodeCompletionContext ) =
405
- let lineStr = doc.Editor.GetLineText( doc.Editor.Caret.Line)
406
-
407
- // Get the long identifier before the current location
408
- // 'residue' is the part after the last dot and 'longName' is before
409
- // e.g. System.Debug.Wri --> "Wri", [ "System"; "Debug"; ]
410
- let lookBack = Parsing.createBackStringReader lineStr ( doc.Editor.Caret.Column - 2 )
411
- match Parsing.tryGetFirst Parsing.parseBackIdentWithResidue lookBack with
412
- | None -> DeclarationSet.Empty
413
- | Some ( residue, longName) ->
414
-
415
- Debug.WriteLine( sprintf " Result: GetDeclarations: line: %d , column: %d , ident: %A \n Line: '%s '" ( doc.Editor.Caret.Line - 1 ) ( doc.Editor.Caret.Column - 1 ) ( longName, residue) lineStr)
416
-
417
- //Review: last parameter is a function has changes since last type check, we always return false here.
418
- //let longName = if longName = [""] then [] else longName
419
- let getDeclarations = info.GetDeclarations( Some( untyped), ( doc.Editor.Caret.Line - 1 , doc.Editor.Caret.Column - 1 ), lineStr, ( longName, residue), fun _ -> false )
420
-
421
- let declarations = Async.RunSynchronously( getDeclarations, ServiceSettings.blockingTimeout)
351
+ let line , col , lineStr = getLineInfoFromOffset( doc.Editor.Caret.Offset, doc.Editor.Document)
352
+ let longName , residue = Parsing.findLongIdentsAndResidue( col, lineStr)
422
353
423
- Debug.WriteLine( sprintf " Result: GetDeclarations: returning %d items" declarations.Items.Length)
424
- declarations
354
+ // Get items & generate output
355
+ try Some ( info.GetDeclarations( None, ( line, col), lineStr, ( longName, residue), fun ( _ , _ ) -> false )
356
+ |> Async.RunSynchronously, residue)
357
+ with :? TimeoutException as e -> None
425
358
426
- /// Get the tool-tip to be displayed at the specified offset (relatively
427
- /// from the beginning of the current document)
359
+ /// Get the tool-tip to be displayed at the specified offset (relatively
360
+ /// from the beginning of the current document)
428
361
member x.GetToolTip ( offset : int , doc : Mono.TextEditor.TextDocument ) =
429
- match crackSymbolText( offset, doc) with
362
+ let line , col , lineStr = getLineInfoFromOffset( offset, doc)
363
+ match Parsing.findLongIdents( col, lineStr) with
430
364
| None -> DataTipText []
431
- | Some( line , col, lineStr , identIsland, currentIdent , token ) ->
365
+ | Some( col, identIsland) ->
432
366
let res = info.GetDataTipText(( line, col), lineStr, identIsland, token)
433
- Debug.WriteLine( " Result: Got something, returning" )
367
+ Debug.WriteLine( " Result: Got something, returning" )
434
368
res
435
369
436
370
member x.GetDeclarationLocation ( offset : int , doc : Mono.TextEditor.TextDocument ) =
437
- match crackSymbolText( offset, doc) with
371
+ let line , col , lineStr = getLineInfoFromOffset( offset, doc)
372
+ match Parsing.findLongIdents( col, lineStr) with
438
373
| None -> DeclNotFound FindDeclFailureReason.Unknown
439
- | Some( line , col, lineStr , identIsland, currentIdent , token ) ->
374
+ | Some( col, identIsland) ->
440
375
let res = info.GetDeclarationLocation(( line, col), lineStr, identIsland, token, true )
441
- Debug.WriteLine( " Result: Got something, returning" )
376
+ Debug.WriteLine( " Result: Got something, returning" )
442
377
res
443
378
444
379
member x.GetMethods ( offset : int , doc : Mono.TextEditor.TextDocument ) =
445
- match crackSymbolTextAtGetMethodsTrigger( offset, doc) with
380
+ let line , col , lineStr = getLineInfoFromOffset ( offset, doc)
381
+ match Parsing.findLongIdentsAtGetMethodsTrigger( col, lineStr) with
446
382
| None -> None
447
- | Some( line , col, lineStr , identIsland, currentIdent , token ) ->
383
+ | Some( col, identIsland) ->
448
384
let res = info.GetMethods(( line, col), lineStr, Some identIsland)
449
- Debug.WriteLine( " Result: Got something, returning" )
385
+ Debug.WriteLine( " Result: Got something, returning" )
450
386
Some ( res.Name, res.Methods)
451
387
452
388
member x.Untyped with get() = untyped
0 commit comments