RoslynCompletionService.cs 1.6 KB
Newer Older
1
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
2 3 4 5 6 7 8

using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;

9
namespace Microsoft.CodeAnalysis.ExternalAccess.LiveShare.Completion
10 11 12
{
    internal class RoslynCompletionService : CompletionServiceWithProviders
    {
D
David Barbet 已提交
13 14
        private readonly CompletionService _originalService;
        private readonly string _language;
15 16 17 18

        public RoslynCompletionService(Workspace workspace, CompletionService originalService, string language)
            : base(workspace)
        {
D
David Barbet 已提交
19 20
            _originalService = originalService ?? throw new ArgumentNullException(nameof(originalService));
            _language = language ?? throw new ArgumentNullException(nameof(language));
21 22 23
            workspace.Options = workspace.Options.WithChangedOption(CompletionOptions.BlockForCompletionItems, language, false);
        }

D
David Barbet 已提交
24
        public override string Language => _language;
25 26 27 28

        public override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, ImmutableHashSet<string> roles = null, OptionSet options = null)
        {
            // Just ask the local service if we should trigger completion based on its rules since that determination is based on just looking at the current buffer.
D
David Barbet 已提交
29
            return _originalService.ShouldTriggerCompletion(text, caretPosition, trigger, roles, options);
30 31 32
        }
    }
}