private TextSpan GetTextChangeSpan(SourceText text, int position, Group quotedPathGroup)
 {
     return(PathCompletionUtilities.GetTextChangeSpan(
                quotedPath: quotedPathGroup.Value,
                quotedPathStart: GetQuotedPathStart(text, position, quotedPathGroup),
                position: position));
 }
 private string GetPathThroughLastSlash(SourceText text, int position, Group quotedPathGroup)
 {
     return(PathCompletionUtilities.GetPathThroughLastSlash(
                quotedPath: quotedPathGroup.Value,
                quotedPathStart: GetQuotedPathStart(text, position, quotedPathGroup),
                position: position));
 }
 private TextSpan GetTextChangeSpan(SyntaxToken stringLiteral, int position)
 {
     return(PathCompletionUtilities.GetTextChangeSpan(
                quotedPath: stringLiteral.ToString(),
                quotedPathStart: stringLiteral.SpanStart,
                position: position));
 }
 private static string GetPathThroughLastSlash(SyntaxToken stringLiteral, int position)
 {
     return(PathCompletionUtilities.GetPathThroughLastSlash(
                quotedPath: stringLiteral.ToString(),
                quotedPathStart: stringLiteral.SpanStart,
                position: position));
 }
        public override bool IsFilterCharacter(CompletionItem completionItem, char ch, string textTypedSoFar)
        {
            // If they've typed '\\', then we do not consider \ to be a filter character.  We want to
            // just commit at this point.
            if (textTypedSoFar == NetworkPath)
            {
                return(false);
            }

            return(PathCompletionUtilities.IsFilterCharacter(completionItem, ch, textTypedSoFar));
        }
Example #6
0
        private ImmutableArray <CompletionItem> GetItems(SourceText text, Document document, int position, CompletionTrigger triggerInfo, CancellationToken cancellationToken)
        {
            var line     = text.Lines.GetLineFromPosition(position);
            var lineText = text.ToString(TextSpan.FromBounds(line.Start, position));
            var match    = s_directiveRegex.Match(lineText);

            if (!match.Success)
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var quotedPathGroup = match.Groups[1];
            var quotedPath      = quotedPathGroup.Value;
            var endsWithQuote   = PathCompletionUtilities.EndsWithQuote(quotedPath);

            if (endsWithQuote && (position >= line.Start + match.Length))
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var buffer   = text.Container.GetTextBuffer();
            var snapshot = text.FindCorrespondingEditorTextSnapshot();

            if (snapshot == null)
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var fileSystem = CurrentWorkingDirectoryDiscoveryService.GetService(snapshot);

            // TODO: https://github.com/dotnet/roslyn/issues/5263
            // Avoid dependency on a specific resolver.
            // The search paths should be provided by specialized workspaces:
            // - InteractiveWorkspace for interactive window
            // - ScriptWorkspace for loose .csx files (we don't have such workspace today)
            var searchPaths = (document.Project.CompilationOptions.SourceReferenceResolver as SourceFileResolver)?.SearchPaths ?? ImmutableArray <string> .Empty;

            var helper = new FileSystemCompletionHelper(
                this,
                GetTextChangeSpan(text, position, quotedPathGroup),
                fileSystem,
                Glyph.OpenFolder,
                Glyph.CSharpFile,
                searchPaths: searchPaths,
                allowableExtensions: new[] { ".csx" },
                itemRules: s_rules);

            var pathThroughLastSlash = this.GetPathThroughLastSlash(text, position, quotedPathGroup);

            return(helper.GetItems(pathThroughLastSlash, documentPath: null));
        }
Example #7
0
        private ImmutableArray <CompletionItem> GetItems(SourceText text, int position, CompletionTriggerInfo triggerInfo, CancellationToken cancellationToken)
        {
            var line     = text.Lines.GetLineFromPosition(position);
            var lineText = text.ToString(TextSpan.FromBounds(line.Start, position));
            var match    = s_directiveRegex.Match(lineText);

            if (!match.Success)
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var quotedPathGroup = match.Groups[1];
            var quotedPath      = quotedPathGroup.Value;
            var endsWithQuote   = PathCompletionUtilities.EndsWithQuote(quotedPath);

            if (endsWithQuote && (position >= line.Start + match.Length))
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var buffer   = text.Container.GetTextBuffer();
            var snapshot = text.FindCorrespondingEditorTextSnapshot();

            if (snapshot == null)
            {
                return(ImmutableArray <CompletionItem> .Empty);
            }

            var fileSystem = CurrentWorkingDirectoryDiscoveryService.GetService(snapshot);

            var searchPaths = ImmutableArray.Create(fileSystem.CurrentDirectory);

            var helper = new FileSystemCompletionHelper(
                this,
                GetTextChangeSpan(text, position, quotedPathGroup),
                fileSystem,
                Glyph.OpenFolder,
                Glyph.CSharpFile,
                searchPaths: searchPaths,
                allowableExtensions: new[] { ".csx" },
                itemRules: ItemRules.Instance);

            var pathThroughLastSlash = this.GetPathThroughLastSlash(text, position, quotedPathGroup);

            return(helper.GetItems(pathThroughLastSlash, documentPath: null));
        }
Example #8
0
 internal override bool IsInsertionTrigger(SourceText text, int characterPosition, OptionSet options)
 {
     return(PathCompletionUtilities.IsTriggerCharacter(text, characterPosition));
 }
 public override bool SendEnterThroughToEditor(CompletionItem completionItem, string textTypedSoFar)
 {
     return(PathCompletionUtilities.SendEnterThroughToEditor(completionItem, textTypedSoFar));
 }
 public override bool IsCommitCharacter(CompletionItem completionItem, char ch, string textTypedSoFar)
 {
     return(PathCompletionUtilities.IsCommitcharacter(completionItem, ch, textTypedSoFar));
 }
 private ICurrentWorkingDirectoryDiscoveryService GetFileSystemDiscoveryService(ITextSnapshot textSnapshot)
 {
     return(PathCompletionUtilities.GetCurrentWorkingDirectoryDiscoveryService(textSnapshot));
 }