Exemplo n.º 1
0
        public override async Task <WorkspaceEdit> Handle(RenameParams request, CancellationToken cancellationToken)
        {
            return(await Task.Run(() =>
            {
                var link = RenameInfo.GetLink(_languageServer, request.TextDocument.Uri.ToUri(), request.Position);
                if (link == null)
                {
                    return new WorkspaceEdit();
                }

                var grouped = link.Group();
                var documentChanges = new List <WorkspaceEditDocumentChange>();
                foreach (var group in grouped)
                {
                    List <TextEdit> edits = new List <TextEdit>();

                    foreach (var renameRange in group.Links)
                    {
                        edits.Add(new TextEdit()
                        {
                            NewText = request.NewName,
                            Range = renameRange
                        });
                    }

                    var document = _languageServer.DocumentHandler.TextDocumentFromUri(group.Uri)?.AsItem();

                    // document will be null if the editor doesn't have the document of the group opened.
                    if (document == null)
                    {
                        ImportedScript importedScript = _languageServer.FileGetter.GetImportedFile(group.Uri);
                        document = new TextDocumentItem()
                        {
                            Uri = group.Uri,
                            Text = importedScript.Content,
                            LanguageId = "ostw"
                        };
                    }

                    WorkspaceEditDocumentChange edit = new WorkspaceEditDocumentChange(new TextDocumentEdit()
                    {
                        Edits = edits.ToArray(),
                        TextDocument = new VersionedTextDocumentIdentifier()
                        {
                            Version = document.Version,
                            Uri = document.Uri
                        }
                    });
                    documentChanges.Add(edit);
                }

                return new WorkspaceEdit()
                {
                    DocumentChanges = documentChanges
                };
            }));
        }
Exemplo n.º 2
0
        // IPrepareRename
        public async Task <RangeOrPlaceholderRange> Handle(PrepareRenameParams request, CancellationToken cancellationToken)
        {
            var link = RenameInfo.GetLink(_languageServer, request.TextDocument.Uri.ToUri(), request.Position);

            if (link == null)
            {
                return(new RangeOrPlaceholderRange(new PlaceholderRange()));
            }

            return(new RangeOrPlaceholderRange(new PlaceholderRange()
            {
                Range = link.Range,
                Placeholder = link.Name
            }));
        }