summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/Protocol.cpp21
-rw-r--r--clang-tools-extra/clangd/Protocol.h25
-rw-r--r--clang-tools-extra/clangd/test/formatting.test10
3 files changed, 15 insertions, 41 deletions
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 4714c6c11da..bd8d0328a5b 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -402,38 +402,23 @@ bool fromJSON(const llvm::json::Value &Params,
O.map("text", R.text);
}
-bool fromJSON(const llvm::json::Value &Params, FormattingOptions &R) {
- llvm::json::ObjectMapper O(Params);
- return O && O.map("tabSize", R.tabSize) &&
- O.map("insertSpaces", R.insertSpaces);
-}
-
-llvm::json::Value toJSON(const FormattingOptions &P) {
- return llvm::json::Object{
- {"tabSize", P.tabSize},
- {"insertSpaces", P.insertSpaces},
- };
-}
-
bool fromJSON(const llvm::json::Value &Params,
DocumentRangeFormattingParams &R) {
llvm::json::ObjectMapper O(Params);
return O && O.map("textDocument", R.textDocument) &&
- O.map("range", R.range) && O.map("options", R.options);
+ O.map("range", R.range);
}
bool fromJSON(const llvm::json::Value &Params,
DocumentOnTypeFormattingParams &R) {
llvm::json::ObjectMapper O(Params);
return O && O.map("textDocument", R.textDocument) &&
- O.map("position", R.position) && O.map("ch", R.ch) &&
- O.map("options", R.options);
+ O.map("position", R.position) && O.map("ch", R.ch);
}
bool fromJSON(const llvm::json::Value &Params, DocumentFormattingParams &R) {
llvm::json::ObjectMapper O(Params);
- return O && O.map("textDocument", R.textDocument) &&
- O.map("options", R.options);
+ return O && O.map("textDocument", R.textDocument);
}
bool fromJSON(const llvm::json::Value &Params, DocumentSymbolParams &R) {
diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index 1ebe8071cda..00846b7a333 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -548,15 +548,13 @@ struct DidChangeConfigurationParams {
};
bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &);
-struct FormattingOptions {
- /// Size of a tab in spaces.
- int tabSize = 0;
-
- /// Prefer spaces over tabs.
- bool insertSpaces = false;
-};
-bool fromJSON(const llvm::json::Value &, FormattingOptions &);
-llvm::json::Value toJSON(const FormattingOptions &);
+// Note: we do not parse FormattingOptions for *FormattingParams.
+// In general, we use a clang-format style detected from common mechanisms
+// (.clang-format files and the -fallback-style flag).
+// It would be possible to override these with FormatOptions, but:
+// - the protocol makes FormatOptions mandatory, so many clients set them to
+// useless values, and we can't tell when to respect them
+// - we also format in other places, where FormatOptions aren't available.
struct DocumentRangeFormattingParams {
/// The document to format.
@@ -564,9 +562,6 @@ struct DocumentRangeFormattingParams {
/// The range to format
Range range;
-
- /// The format options
- FormattingOptions options;
};
bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &);
@@ -579,18 +574,12 @@ struct DocumentOnTypeFormattingParams {
/// The character that has been typed.
std::string ch;
-
- /// The format options.
- FormattingOptions options;
};
bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &);
struct DocumentFormattingParams {
/// The document to format.
TextDocumentIdentifier textDocument;
-
- /// The format options
- FormattingOptions options;
};
bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &);
diff --git a/clang-tools-extra/clangd/test/formatting.test b/clang-tools-extra/clangd/test/formatting.test
index 9f8f3db9a5a..490044cf98e 100644
--- a/clang-tools-extra/clangd/test/formatting.test
+++ b/clang-tools-extra/clangd/test/formatting.test
@@ -3,7 +3,7 @@
---
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"int foo ( int x ) {\n x = x+1;\n return x;\n }"}}}
---
-{"jsonrpc":"2.0","id":1,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+{"jsonrpc":"2.0","id":1,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}}}}
# CHECK: "id": 1,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": [
@@ -65,12 +65,12 @@
#
#
---
-{"jsonrpc":"2.0","id":2,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":2},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+{"jsonrpc":"2.0","id":2,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":2},"end":{"line":1,"character":12}}}}
# CHECK: "id": 2,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": []
---
-{"jsonrpc":"2.0","id":3,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+{"jsonrpc":"2.0","id":3,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"}}}
# CHECK: "id": 3,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": [
@@ -130,14 +130,14 @@
---
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":9},"contentChanges":[{"text":"int foo(int x) {\n x = x + 1;\n return x;\n}"}]}}
---
-{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"}}}
# CHECK: "id": 4,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": []
---
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":5},"contentChanges":[{"text":"int foo ( int x ) {\n x = x + 1;\n return x;\n}"}]}}
---
-{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}}
+{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":3,"character":1},"ch":"}"}}
# CHECK: "id": 5,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": [
OpenPOWER on IntegriCloud