mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-30 03:52:35 +00:00 
			
		
		
		
	Implement .clang-format style management
If we can't find a .clang-format file for the given file, default to Chromium style with the tab/spaces configuration that was provided by the client.
This commit is contained in:
		
							parent
							
								
									19341c18cd
								
							
						
					
					
						commit
						aa4e5e7e5b
					
				| @ -15,12 +15,24 @@ ClangFormat::ClangFormat(llvm::StringRef document_filename, | |||||||
|       insert_spaces_(insert_spaces) {} |       insert_spaces_(insert_spaces) {} | ||||||
| ClangFormat::~ClangFormat(){}; | ClangFormat::~ClangFormat(){}; | ||||||
| 
 | 
 | ||||||
|  | static FormatStyle::LanguageKind getLanguageKindFromFilename( | ||||||
|  |     llvm::StringRef filename) { | ||||||
|  |   if (filename.endswith(".m") || filename.endswith(".mm")) { | ||||||
|  |     return FormatStyle::LK_ObjC; | ||||||
|  |   } | ||||||
|  |   return FormatStyle::LK_Cpp; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| std::vector<Replacement> ClangFormat::FormatWholeDocument() { | std::vector<Replacement> ClangFormat::FormatWholeDocument() { | ||||||
|   // TODO: Construct a valid style.
 |   const auto language_kind = getLanguageKindFromFilename(document_filename_); | ||||||
|   FormatStyle style = getChromiumStyle(FormatStyle::LK_Cpp); |   FormatStyle predefined_style; | ||||||
|   style.UseTab = insert_spaces_ ? FormatStyle::UseTabStyle::UT_Never |   getPredefinedStyle("chromium", language_kind, &predefined_style); | ||||||
|                                 : FormatStyle::UseTabStyle::UT_Always; |   auto style = getStyle("file", document_filename_, "chromium"); | ||||||
|   style.IndentWidth = tab_size_; |   if (style == predefined_style) { | ||||||
|  |     style.UseTab = insert_spaces_ ? FormatStyle::UseTabStyle::UT_Never | ||||||
|  |                                   : FormatStyle::UseTabStyle::UT_Always; | ||||||
|  |     style.IndentWidth = tab_size_; | ||||||
|  |   } | ||||||
|   auto format_result = reformat(style, document_, ranges_, document_filename_); |   auto format_result = reformat(style, document_, ranges_, document_filename_); | ||||||
|   return std::vector<Replacement>(format_result.begin(), format_result.end()); |   return std::vector<Replacement>(format_result.begin(), format_result.end()); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user