[PATCH] D67224: [clangd] Enable completions with fixes in VSCode

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D67224#1804513 , @nridge wrote:

> Just throwing a wild idea out there: what if we used 
> `textDocument/onTypeFormatting` to replace the `.` with `->` as soon as it's 
> typed?


There is no way we can do this with proper latency. `onTypeFormatting` can't 
wait for the parsing to complete and we need the parsing to complete in order 
to determine the type of expression to the left of `.` or `->`.
Moreover, in cases like `unique_ptr().` we can't know whether the user wants 
`.` or `->` before we pick the completion item. Both `.` and `->` are allowed 
in this context.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67224/new/

https://reviews.llvm.org/D67224



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67224: [clangd] Enable completions with fixes in VSCode

2020-01-04 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Just throwing a wild idea out there: what if we used 
`textDocument/onTypeFormatting` to replace the `.` with `->` as soon as it's 
typed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67224/new/

https://reviews.llvm.org/D67224



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67224: [clangd] Enable completions with fixes in VSCode

2019-09-05 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov planned changes to this revision.
ilya-biryukov added a comment.

Changing behavior of clangd might affect other clients.
It would be nice to find alternative ways to fix this.

Nevertheless, posting this here as an example of a potential workaround for the 
problem.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67224/new/

https://reviews.llvm.org/D67224



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67224: [clangd] Enable completions with fixes in VSCode

2019-09-05 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, mgrang, jkorous, 
MaskRay.
Herald added a project: clang.

Currently, the completions are not shown to the user as VSCode tries to match
'filterText' against the text in the edit range. Since the text contains '.'
or '->', we end up trying to match 'field' against '->field' and fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67224

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
@@ -65,6 +65,14 @@
   }
 }
 
+class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
+  fillClientCapabilities(capabilities: vscodelc.ClientCapabilities): void {
+const extendedCompletionCapabilities: any = 
capabilities.textDocument.completion;
+extendedCompletionCapabilities.editsNearCursor = true;
+  }
+  initialize(capabilities: vscodelc.ServerCapabilities, documentSelector: 
(string | { language: string; scheme?: string; pattern?: string; } | { 
language?: string; scheme: string; pattern?: string; } | { language?: string; 
scheme?: string; pattern: string; })[]): void {
+  }
+}
 /**
  *  this method is called when your extension is activate
  *  your extension is activated the very first time the command is executed
@@ -114,6 +122,7 @@
   context.subscriptions.push(
   vscode.Disposable.from(semanticHighlightingFeature));
   clangdClient.registerFeature(semanticHighlightingFeature);
+  clangdClient.registerFeature(new EnableEditsNearCursorFeature);
   console.log('Clang Language Server is now active!');
   context.subscriptions.push(clangdClient.start());
   context.subscriptions.push(vscode.commands.registerCommand(
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -175,9 +175,13 @@
   // thse includes may not be accurate for all of them.
   llvm::SmallVector Includes;
 
+  struct FixIt {
+std::string Before;
+TextEdit Edit;
+  };
   /// Holds information about small corrections that needs to be done. Like
   /// converting '->' to '.' on member access.
-  std::vector FixIts;
+  std::vector FixIts;
 
   /// Holds the range of the token we are going to replace with this 
completion.
   Range CompletionTokenRange;
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -277,12 +277,25 @@
   Completion.Name.back() == '/')
 Completion.Kind = CompletionItemKind::Folder;
   for (const auto  : C.SemaResult->FixIts) {
-Completion.FixIts.push_back(toTextEdit(
-FixIt, ASTCtx->getSourceManager(), ASTCtx->getLangOpts()));
+// FIXME: this should live in SourceCode.h
+auto  = ASTCtx->getSourceManager();
+CharSourceRange Range = Lexer::makeFileCharRange(FixIt.RemoveRange, SM,
+ 
ASTCtx->getLangOpts());
+FileID FID;
+unsigned StartOffset;
+std::tie(FID, StartOffset) = SM.getDecomposedLoc(Range.getBegin());
+
+std::string Code = SM.getBufferData(FID).substr(
+StartOffset, SM.getFileOffset(Range.getEnd()) - StartOffset);
+
+Completion.FixIts.push_back(CodeCompletion::FixIt{
+std::move(Code), toTextEdit(FixIt, ASTCtx->getSourceManager(),
+ASTCtx->getLangOpts())});
   }
-  llvm::sort(Completion.FixIts, [](const TextEdit , const TextEdit ) {
-return std::tie(X.range.start.line, X.range.start.character) <
-   std::tie(Y.range.start.line, Y.range.start.character);
+  llvm::sort(Completion.FixIts, [](const CodeCompletion::FixIt ,
+   const CodeCompletion::FixIt ) {
+return std::tie(X.Edit.range.start.line, X.Edit.range.start.character) 
<
+   std::tie(Y.Edit.range.start.line, Y.Edit.range.start.character);
   });
   Completion.Deprecated |=
   (C.SemaResult->Availability == CXAvailability_Deprecated);
@@ -1817,11 +1830,12 @@
   // is mainly to help LSP clients again, so that changes do not effect each
   // other.
   for (const auto  : FixIts) {
-if (isRangeConsecutive(FixIt.range, LSP.textEdit->range)) {
-  LSP.textEdit->newText = FixIt.newText + LSP.textEdit->newText;
-  LSP.textEdit->range.start = FixIt.range.start;
+if (isRangeConsecutive(FixIt.Edit.range,