[PATCH] D36150: [clangd] LSP extension to switch between source/header file

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 07:48:33 PDT 2017


arphaman added inline comments.


================
Comment at: clangd/ClangdServer.cpp:292
+
+  if (path.compare(path.length() - 4, 4, ".cpp") == 0) {
+    path = path.substr(0, (path.length() - 4));
----------------
malaperle wrote:
> this won't work for other extensions, we need to make this more generic. I believe you had a list of typical source files extensions and header extensions before?
LLVM has a wonderful `sys::path` library for path manipulations. You could rewrite these checks like this:

```
if (llvm::sys::path::extension(path) == ".cpp") {
 SmallString<128> NewPath = path;
 llvm::sys::path::replace_extension(NewPath, "h");
 return "\"" + NewPath.str() + "\"";
}
```


https://reviews.llvm.org/D36150





More information about the cfe-commits mailing list