2017-05-16 17:38:59 +08:00
|
|
|
//===--- ClangdLSPServer.h - LSP server --------------------------*- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDLSPSERVER_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDLSPSERVER_H
|
|
|
|
|
|
|
|
#include "ClangdServer.h"
|
|
|
|
#include "Path.h"
|
|
|
|
#include "Protocol.h"
|
|
|
|
#include "clang/Tooling/Core/Replacement.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
class JSONOutput;
|
|
|
|
|
2017-05-16 22:40:30 +08:00
|
|
|
/// This class provides implementation of an LSP server, glueing the JSON
|
|
|
|
/// dispatch and ClangdServer together.
|
2017-05-16 17:38:59 +08:00
|
|
|
class ClangdLSPServer {
|
|
|
|
public:
|
|
|
|
ClangdLSPServer(JSONOutput &Out, bool RunSynchronously);
|
|
|
|
|
2017-05-16 22:40:30 +08:00
|
|
|
/// Run LSP server loop, receiving input for it from \p In. \p In must be
|
|
|
|
/// opened in binary mode. Output will be written using Out variable passed to
|
|
|
|
/// class constructor. This method must not be executed more than once for
|
|
|
|
/// each instance of ClangdLSPServer.
|
|
|
|
void run(std::istream &In);
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2017-05-16 22:40:30 +08:00
|
|
|
private:
|
|
|
|
class LSPProtocolCallbacks;
|
|
|
|
class LSPDiagnosticsConsumer;
|
2017-05-16 17:38:59 +08:00
|
|
|
|
|
|
|
std::vector<clang::tooling::Replacement>
|
|
|
|
getFixIts(StringRef File, const clangd::Diagnostic &D);
|
|
|
|
|
|
|
|
/// Function that will be called on a separate thread when diagnostics are
|
|
|
|
/// ready. Sends the Dianostics to LSP client via Out.writeMessage and caches
|
|
|
|
/// corresponding fixits in the FixItsMap.
|
|
|
|
void consumeDiagnostics(PathRef File,
|
|
|
|
std::vector<DiagWithFixIts> Diagnostics);
|
|
|
|
|
|
|
|
JSONOutput &Out;
|
2017-05-16 22:40:30 +08:00
|
|
|
/// Used to indicate that the 'shutdown' request was received from the
|
|
|
|
/// Language Server client.
|
|
|
|
/// It's used to break out of the LSP parsing loop.
|
|
|
|
bool IsDone = false;
|
2017-05-16 17:38:59 +08:00
|
|
|
|
|
|
|
std::mutex FixItsMutex;
|
|
|
|
typedef std::map<clangd::Diagnostic, std::vector<clang::tooling::Replacement>>
|
|
|
|
DiagnosticToReplacementMap;
|
|
|
|
/// Caches FixIts per file and diagnostics
|
|
|
|
llvm::StringMap<DiagnosticToReplacementMap> FixItsMap;
|
|
|
|
// Server must be the last member of the class to allow its destructor to exit
|
|
|
|
// the worker thread that may otherwise run an async callback on partially
|
|
|
|
// destructed instance of ClangdLSPServer.
|
|
|
|
ClangdServer Server;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|