public Task <TextEdit[]> FormatDocumentRange(TextEditor editor, CancellationToken token)
        {
            if (!IsStarted)
            {
                return(Task.FromResult <TextEdit[]> (null));
            }

            if (!IsDocumentFormattingProvider)
            {
                Log("Document formatting is not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentRangeFormattingName, editor.FileName);
                return(Task.FromResult <TextEdit[]> (null));
            }

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentRangeFormattingName, editor.FileName);

            var message = new DocumentRangeFormattingParams {
                TextDocument = TextDocumentIdentifierFactory.Create(editor.FileName),
                Options      = new FormattingOptions {
                    InsertSpaces = editor.Options.TabsToSpaces,
                    TabSize      = editor.Options.TabSize
                },
                Range = new Range {
                    Start = editor.SelectionRegion.Begin.CreatePosition(),
                    End   = editor.SelectionRegion.End.CreatePosition()
                }
            };

            return(jsonRpc.InvokeWithParameterObjectAsync(
                       Methods.TextDocumentRangeFormatting,
                       message,
                       token));
        }
        public Task <WorkspaceEdit> Rename(FilePath fileName, Position position, string newName, CancellationToken token)
        {
            if (!IsStarted)
            {
                return(Task.FromResult <WorkspaceEdit> (null));
            }

            if (!IsRenameProvider)
            {
                Log("Rename is not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentRenameName, fileName);
                return(Task.FromResult <WorkspaceEdit> (null));
            }

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentRenameName, fileName);

            var message = new RenameParams {
                TextDocument = TextDocumentIdentifierFactory.Create(fileName),
                NewName      = newName,
                Position     = position
            };

            return(jsonRpc.InvokeWithParameterObjectAsync(
                       Methods.TextDocumentRename,
                       message,
                       token));
        }
        public Task TextChanged(FilePath fileName, int version, TextChangeEventArgs e, TextEditor editor)
        {
            Runtime.AssertMainThread();

            if (!IsStarted)
            {
                return(Task.FromResult(0));
            }

            if (!IsDocumentSyncSupported)
            {
                Log("Document sync not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentDidChangeName, fileName);
                return(Task.FromResult(0));
            }

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentDidChangeName, fileName);

            var message = new DidChangeTextDocumentParams {
                TextDocument   = TextDocumentIdentifierFactory.Create(fileName, version),
                ContentChanges = e.CreateTextDocumentContentChangeEvents(editor, IsDocumentSyncFull)
                                 .ToArray()
            };

            return(jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidChange, message));
        }
        public async Task <Location[]> FindDefinitions(FilePath fileName, Position position, CancellationToken token)
        {
            if (!IsStarted)
            {
                return(Array.Empty <Location> ());
            }

            if (!IsDefinitionProvider)
            {
                Log("Find definitions is not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentDefinitionName, fileName);
                return(Array.Empty <Location> ());
            }

            var message = new TextDocumentPositionParams {
                TextDocument = TextDocumentIdentifierFactory.Create(fileName),
                Position     = position
            };

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentDefinitionName, fileName);

            var result = await jsonRpc.InvokeWithParameterObjectAsync(
                Methods.TextDocumentDefinition,
                message,
                token);

            return(ConvertToLocations(result));
        }
        public Task <Location[]> GetReferences(FilePath fileName, Position position, CancellationToken token)
        {
            if (!IsStarted)
            {
                return(Task.FromResult(new Location[0]));
            }

            if (!IsReferencesProvider)
            {
                Log("Get references is not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentReferencesName, fileName);
                return(Task.FromResult(new Location [0]));
            }

            var message = new ReferenceParams {
                Context = new ReferenceContext {
                    IncludeDeclaration = true
                },
                TextDocument = TextDocumentIdentifierFactory.Create(fileName),
                Position     = position
            };

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentReferencesName, fileName);

            return(jsonRpc.InvokeWithParameterObjectAsync(
                       Methods.TextDocumentReferences,
                       message,
                       token));
        }
 static TextDocumentPositionParams CreateTextDocumentPosition(FilePath fileName, int column, int line)
 {
     return(new TextDocumentPositionParams {
         Position = new Position {
             Character = column,
             Line = line
         },
         TextDocument = TextDocumentIdentifierFactory.Create(fileName)
     });
 }
        Task SendCloseDocumentMessage(FilePath fileName)
        {
            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentDidCloseName, fileName);

            var message = new DidCloseTextDocumentParams {
                TextDocument = TextDocumentIdentifierFactory.Create(fileName)
            };

            return(jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidClose, message));
        }
        public async Task <Command[]> GetCodeActions(
            FilePath fileName,
            Range range,
            Diagnostic[] diagnostics,
            CancellationToken token)
        {
            if (!IsStarted)
            {
                return(null);
            }

            if (!IsCodeActionProvider)
            {
                Log("Code actions are not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentCodeActionName, fileName);
                return(null);
            }

            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentCodeActionName, fileName);

            var message = new CodeActionParams {
                TextDocument = TextDocumentIdentifierFactory.Create(fileName),
                Context      = new CodeActionContext {
                    Diagnostics = diagnostics
                },
                Range = range
            };

            SumType <Command, CodeAction>[] result = await jsonRpc.InvokeWithParameterObjectAsync(
                Methods.TextDocumentCodeAction,
                message,
                token);

            return(result
                   .Select(item => item.GetCommand())
                   .Where(command => command != null)
                   .ToArray());
        }