Compare commits

...

3 Commits

Author SHA1 Message Date
Bastian Beranek
07175355f3
Merge 874be9223a into 4331c89586 2024-12-06 23:06:38 +00:00
Fangrui Song
4331c89586 Adapt llvmorg-20-init-12964-gdf9a14d7bbf1: createDiagnostics 2024-11-23 18:33:49 -08:00
Bastian Beranek
874be9223a Workaround inconsistency in intersection between ranges.
Sadly there is some confusion about ranges in the LSP protocol. It turns out
that VS code, when requesting code actions, sends range s,e in the request,
with the associated meaning that e is _included_ in the range, i.e. the interval
is [s,e]. The emacs lsp-mode also uses this convention.

However, the protocl specifies that the end in the range s,e should not be part
of the interval, i.e. s,e is supposed to correspond to [s,e[:

https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#range

This was brought up with emacs-lsp, where the maintainer stated that he prefers
to stay compatbile with VS code rather than the protocol, and that the protocol
should likely be amended:

https://github.com/emacs-lsp/lsp-mode/issues/3144

If that is the case, ccls intersection between ranges should be amended for now,
such that the end parameter is part of the range.
2021-10-23 12:18:00 +02:00
4 changed files with 21 additions and 8 deletions

View File

@ -124,9 +124,11 @@ buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
args.insert(args.begin() + 1, std::begin(arr), std::end(arr)); args.insert(args.begin() + 1, std::begin(arr), std::end(arr));
} }
IntrusiveRefCntPtr<DiagnosticsEngine> diags( IntrusiveRefCntPtr<DiagnosticsEngine> diags(CompilerInstance::createDiagnostics(
CompilerInstance::createDiagnostics(new DiagnosticOptions, #if LLVM_VERSION_MAJOR >= 20
new IgnoringDiagConsumer, true)); *vfs,
#endif
new DiagnosticOptions, new IgnoringDiagConsumer, true));
#if LLVM_VERSION_MAJOR < 12 // llvmorg-12-init-5498-g257b29715bb #if LLVM_VERSION_MAJOR < 12 // llvmorg-12-init-5498-g257b29715bb
driver::Driver d(args[0], llvm::sys::getDefaultTargetTriple(), *diags, vfs); driver::Driver d(args[0], llvm::sys::getDefaultTargetTriple(), *diags, vfs);
#else #else

View File

@ -1312,7 +1312,11 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
IndexDiags dc; IndexDiags dc;
auto clang = std::make_unique<CompilerInstance>(pch); auto clang = std::make_unique<CompilerInstance>(pch);
clang->setInvocation(std::move(ci)); clang->setInvocation(std::move(ci));
clang->createDiagnostics(&dc, false); clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&dc, false);
clang->getDiagnostics().setIgnoreAllWarnings(true); clang->getDiagnostics().setIgnoreAllWarnings(true);
clang->setTarget(TargetInfo::CreateTargetInfo( clang->setTarget(TargetInfo::CreateTargetInfo(
clang->getDiagnostics(), clang->getInvocation().TargetOpts)); clang->getDiagnostics(), clang->getInvocation().TargetOpts));

View File

@ -100,7 +100,7 @@ struct lsRange {
return start <= o.start && o.end <= end; return start <= o.start && o.end <= end;
} }
bool intersects(const lsRange &o) const { bool intersects(const lsRange &o) const {
return start < o.end && o.start < end; return start <= o.end && o.start <= end;
} }
}; };

View File

@ -288,7 +288,11 @@ buildCompilerInstance(Session &session, std::unique_ptr<CompilerInvocation> ci,
auto clang = std::make_unique<CompilerInstance>(session.pch); auto clang = std::make_unique<CompilerInstance>(session.pch);
clang->setInvocation(std::move(ci)); clang->setInvocation(std::move(ci));
clang->createDiagnostics(&dc, false); clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&dc, false);
clang->setTarget(TargetInfo::CreateTargetInfo( clang->setTarget(TargetInfo::CreateTargetInfo(
clang->getDiagnostics(), clang->getInvocation().TargetOpts)); clang->getDiagnostics(), clang->getInvocation().TargetOpts));
if (!clang->hasTarget()) if (!clang->hasTarget())
@ -368,8 +372,11 @@ void buildPreamble(Session &session, CompilerInvocation &ci,
#endif #endif
StoreDiags dc(task.path); StoreDiags dc(task.path);
IntrusiveRefCntPtr<DiagnosticsEngine> de = IntrusiveRefCntPtr<DiagnosticsEngine> de = CompilerInstance::createDiagnostics(
CompilerInstance::createDiagnostics(&ci.getDiagnosticOpts(), &dc, false); #if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&ci.getDiagnosticOpts(), &dc, false);
if (oldP) { if (oldP) {
std::lock_guard lock(session.wfiles->mutex); std::lock_guard lock(session.wfiles->mutex);
for (auto &include : oldP->includes) for (auto &include : oldP->includes)