Exemple #1
0
        public CompletionHandler(
            IGlobalOptionService globalOptions,
            [ImportMany] IEnumerable <Lazy <CompletionProvider, CompletionProviderMetadata> > completionProviders)
        {
            _globalOptions = globalOptions;

            _csharpTriggerCharacters = completionProviders.Where(lz => lz.Metadata.Language == LanguageNames.CSharp).SelectMany(
                lz => CommonCompletionUtilities.GetTriggerCharacters(lz.Value)).ToImmutableHashSet();
            _vbTriggerCharacters = completionProviders.Where(lz => lz.Metadata.Language == LanguageNames.VisualBasic).SelectMany(
                lz => CommonCompletionUtilities.GetTriggerCharacters(lz.Value)).ToImmutableHashSet();
        }
        public ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities)
        {
            var capabilities = new ServerCapabilities();

            if (clientCapabilities is VSInternalClientCapabilities vsClientCapabilities && vsClientCapabilities.SupportsVisualStudioExtensions)
            {
                capabilities = GetVSServerCapabilities();
            }

            var commitCharacters  = CompletionRules.Default.DefaultCommitCharacters.Select(c => c.ToString()).ToArray();
            var triggerCharacters = _completionProviders.SelectMany(
                lz => CommonCompletionUtilities.GetTriggerCharacters(lz.Value)).Distinct().Select(c => c.ToString()).ToArray();

            capabilities.DefinitionProvider     = true;
            capabilities.RenameProvider         = true;
            capabilities.ImplementationProvider = true;
            capabilities.CodeActionProvider     = new CodeActionOptions {
                CodeActionKinds = new[] { CodeActionKind.QuickFix, CodeActionKind.Refactor }, ResolveProvider = true
            };
            capabilities.CompletionProvider = new VisualStudio.LanguageServer.Protocol.CompletionOptions
            {
                ResolveProvider     = true,
                AllCommitCharacters = commitCharacters,
                TriggerCharacters   = triggerCharacters,
            };

            capabilities.SignatureHelpProvider = new SignatureHelpOptions {
                TriggerCharacters = new[] { "(", "," }
            };
            capabilities.DocumentSymbolProvider           = true;
            capabilities.WorkspaceSymbolProvider          = true;
            capabilities.DocumentFormattingProvider       = true;
            capabilities.DocumentRangeFormattingProvider  = true;
            capabilities.DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions {
                FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" }
            };
            capabilities.ReferencesProvider     = true;
            capabilities.FoldingRangeProvider   = true;
            capabilities.ExecuteCommandProvider = new ExecuteCommandOptions();
            capabilities.TextDocumentSync       = new TextDocumentSyncOptions
            {
                Change    = TextDocumentSyncKind.Incremental,
                OpenClose = true
            };

            capabilities.HoverProvider = true;

            capabilities.SemanticTokensOptions = new SemanticTokensOptions
            {
                Full = new SemanticTokensFullOptions {
                    Delta = true
                },
                Range  = true,
                Legend = new SemanticTokensLegend
                {
                    TokenTypes     = SemanticTokenTypes.AllTypes.Concat(SemanticTokensHelpers.RoslynCustomTokenTypes).ToArray(),
                    TokenModifiers = new string[] { SemanticTokenModifiers.Static }
                }
            };

            return(capabilities);
        }
        public ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities)
        {
            var capabilities = new ServerCapabilities();

            if (clientCapabilities is VSInternalClientCapabilities vsClientCapabilities && vsClientCapabilities.SupportsVisualStudioExtensions)
            {
                capabilities = GetVSServerCapabilities();
            }

            var commitCharacters  = CompletionRules.Default.DefaultCommitCharacters.Select(c => c.ToString()).ToArray();
            var triggerCharacters = _completionProviders.SelectMany(
                lz => CommonCompletionUtilities.GetTriggerCharacters(lz.Value)).Distinct().Select(c => c.ToString()).ToArray();

            capabilities.DefinitionProvider     = true;
            capabilities.RenameProvider         = true;
            capabilities.ImplementationProvider = true;
            capabilities.CodeActionProvider     = new CodeActionOptions {
                CodeActionKinds = new[] { CodeActionKind.QuickFix, CodeActionKind.Refactor }, ResolveProvider = true
            };
            capabilities.CompletionProvider = new VisualStudio.LanguageServer.Protocol.CompletionOptions
            {
                ResolveProvider     = true,
                AllCommitCharacters = commitCharacters,
                TriggerCharacters   = triggerCharacters,
            };

            capabilities.SignatureHelpProvider = new SignatureHelpOptions {
                TriggerCharacters = new[] { "(", "," }
            };
            capabilities.DocumentSymbolProvider           = true;
            capabilities.WorkspaceSymbolProvider          = true;
            capabilities.DocumentFormattingProvider       = true;
            capabilities.DocumentRangeFormattingProvider  = true;
            capabilities.DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions {
                FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" }
            };
            capabilities.ReferencesProvider     = true;
            capabilities.FoldingRangeProvider   = true;
            capabilities.ExecuteCommandProvider = new ExecuteCommandOptions();
            capabilities.TextDocumentSync       = new TextDocumentSyncOptions
            {
                Change    = TextDocumentSyncKind.Incremental,
                OpenClose = true
            };

            capabilities.HoverProvider = true;

            // Using only range handling has shown to be more performant than using a combination of full/edits/range handling,
            // especially for larger files. With range handling, we only need to compute tokens for whatever is in view, while
            // with full/edits handling we need to compute tokens for the entire file and then potentially run a diff between
            // the old and new tokens.
            capabilities.SemanticTokensOptions = new SemanticTokensOptions
            {
                Full   = false,
                Range  = true,
                Legend = new SemanticTokensLegend
                {
                    TokenTypes     = SemanticTokenTypes.AllTypes.Concat(SemanticTokensHelpers.RoslynCustomTokenTypes).ToArray(),
                    TokenModifiers = new string[] { SemanticTokenModifiers.Static }
                }
            };

            return(capabilities);
        }