[clang-tools-extra] [clangd] Avoid libFormat's objective-c guessing heuristic where possible (PR #84133)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 11 00:09:40 PDT 2024


================
@@ -166,14 +166,29 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
 std::optional<std::string> getCanonicalPath(const FileEntryRef F,
                                             FileManager &FileMgr);
 
+/// A flag passed to getFormatStyleForFile() that specifies what kind of
+/// formatting operation the returned FormatStyle will be used for.
+enum class FormatKind {
+  // Formatting a snippet of synthesized code (e.g. a code snippet
+  // shown in a hover) that's not part of the main file.
+  Snippet,
+  // Formatting edits made by an editor action such as code completion
+  // or rename.
+  Replacements,
+  // Formatting the entire main file (or a range selected by the user,
+  // which can be arbitrarily long).
+  EntireFileOrRange
+};
+
 /// Choose the clang-format style we should apply to a certain file.
 /// This will usually use FS to look for .clang-format directories.
 /// FIXME: should we be caching the .clang-format file search?
 /// This uses format::DefaultFormatStyle and format::DefaultFallbackStyle,
 /// though the latter may have been overridden in main()!
 format::FormatStyle getFormatStyleForFile(llvm::StringRef File,
----------------
HighCommander4 wrote:

Sure, I added a unit test which checks the detected language in various cases, including checking that the new `FormatFile` flag successfully bypasses the language guessing heuristic

https://github.com/llvm/llvm-project/pull/84133


More information about the cfe-commits mailing list