Esempio n. 1
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));
        }
Esempio n. 2
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));
        }
        internal static string GetBaseDirectory(SourceText text, Document document)
        {
            string result;

            if (document.Project.IsSubmission)
            {
                var buffer   = text.Container.GetTextBuffer();
                var snapshot = text.FindCorrespondingEditorTextSnapshot();
                if (snapshot == null)
                {
                    return(null);
                }

                result = CurrentWorkingDirectoryDiscoveryService.GetService(snapshot).WorkingDirectory;
            }
            else
            {
                result = PathUtilities.GetDirectoryName(document.FilePath);
            }

            return(PathUtilities.IsAbsolute(result) ? result : null);
        }
Esempio n. 4
0
 private static ICurrentWorkingDirectoryDiscoveryService GetFileSystemDiscoveryService(ITextSnapshot textSnapshot)
 {
     return(CurrentWorkingDirectoryDiscoveryService.GetService(textSnapshot));
 }