private static void TestCase(string input, string expectedBasePath = null) { var cursorIndex = input.IndexOf('|'); if (cursorIndex < 0 || cursorIndex != input.LastIndexOf('|')) { throw new ArgumentException("Test case must have exactly one | character for the cursor position.", "input"); } input = input.Remove(cursorIndex, 1); Tuple <string, Span> expected = null; var spanStart = input.IndexOf('<'); if (spanStart < 0 && expectedBasePath != null) { throw new ArgumentException("If no activation range is specified in the input, expectedPath should not be passed.", "expectedPath"); } if (spanStart >= 0) { if (spanStart <= cursorIndex) { cursorIndex--; // Decrement the cursor to allow for the removed character } input = input.Remove(spanStart, 1); int spanEnd = input.IndexOf('>'); if (spanEnd < spanStart || spanEnd != input.LastIndexOf('>') || input.Contains('<')) { throw new ArgumentException("Test case must have at most one range enclosed in <angle brackets> for the expected IntelliSense activation range.", "input"); } if (spanEnd < cursorIndex) { cursorIndex--; // Decrement the cursor to allow for the removed character } input = input.Remove(spanEnd, 1); expected = Tuple.Create(expectedBasePath, Span.FromBounds(spanStart, spanEnd)); } NodeModuleCompletionUtils.FindCompletionInfo(input, cursorIndex).Should().Be(expected); }
public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { var position = session.GetTriggerPoint(_buffer).GetPoint(_buffer.CurrentSnapshot); var line = position.GetContainingLine(); if (line == null) { return; } int linePos = position - line.Start.Position; var info = NodeModuleCompletionUtils.FindCompletionInfo(line.GetText(), linePos); if (info == null) { return; } var callingFilename = _buffer.GetFileName(); var baseFolder = Path.GetDirectoryName(callingFilename); IEnumerable <Intel.Completion> results; if (String.IsNullOrWhiteSpace(info.Item1)) { results = GetRootCompletions(baseFolder); } else { results = GetRelativeCompletions(NodeModuleService.ResolvePath(baseFolder, info.Item1)); // Show completions for ../../ if (parentTraversalRegex.IsMatch(info.Item1)) { results = new[] { parentFolder } }