2017-02-07 18:28:20 +08:00
|
|
|
//===--- ProtocolHandlers.h - LSP callbacks ---------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the actions performed when the server gets a specific
|
|
|
|
// request.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOLHANDLERS_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOLHANDLERS_H
|
|
|
|
|
|
|
|
#include "JSONRPCDispatcher.h"
|
|
|
|
#include "Protocol.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2017-03-02 00:16:29 +08:00
|
|
|
class ASTManager;
|
2017-02-07 18:28:20 +08:00
|
|
|
class DocumentStore;
|
|
|
|
|
|
|
|
struct InitializeHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
InitializeHandler(JSONOutput &Output) : Handler(Output) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
|
|
|
|
writeMessage(
|
|
|
|
R"({"jsonrpc":"2.0","id":)" + ID +
|
|
|
|
R"(,"result":{"capabilities":{
|
|
|
|
"textDocumentSync": 1,
|
|
|
|
"documentFormattingProvider": true,
|
2017-02-16 18:49:46 +08:00
|
|
|
"documentRangeFormattingProvider": true,
|
2017-03-02 00:16:29 +08:00
|
|
|
"documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
|
2017-04-04 17:46:39 +08:00
|
|
|
"codeActionProvider": true,
|
|
|
|
"completionProvider": {"resolveProvider": false, "triggerCharacters": [".",">"]}
|
2017-02-07 18:28:20 +08:00
|
|
|
}}})");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShutdownHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
ShutdownHandler(JSONOutput &Output) : Handler(Output) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
|
2017-02-11 01:25:38 +08:00
|
|
|
IsDone = true;
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
2017-02-11 01:25:38 +08:00
|
|
|
|
|
|
|
bool isDone() const { return IsDone; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsDone = false;
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TextDocumentDidOpenHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
TextDocumentDidOpenHandler(JSONOutput &Output, DocumentStore &Store)
|
|
|
|
: Handler(Output), Store(Store) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleNotification(llvm::yaml::MappingNode *Params) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentStore &Store;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextDocumentDidChangeHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
TextDocumentDidChangeHandler(JSONOutput &Output, DocumentStore &Store)
|
|
|
|
: Handler(Output), Store(Store) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleNotification(llvm::yaml::MappingNode *Params) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentStore &Store;
|
|
|
|
};
|
|
|
|
|
2017-02-16 18:49:46 +08:00
|
|
|
struct TextDocumentOnTypeFormattingHandler : Handler {
|
|
|
|
TextDocumentOnTypeFormattingHandler(JSONOutput &Output, DocumentStore &Store)
|
|
|
|
: Handler(Output), Store(Store) {}
|
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentStore &Store;
|
|
|
|
};
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct TextDocumentRangeFormattingHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
TextDocumentRangeFormattingHandler(JSONOutput &Output, DocumentStore &Store)
|
|
|
|
: Handler(Output), Store(Store) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentStore &Store;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextDocumentFormattingHandler : Handler {
|
2017-02-10 22:08:40 +08:00
|
|
|
TextDocumentFormattingHandler(JSONOutput &Output, DocumentStore &Store)
|
|
|
|
: Handler(Output), Store(Store) {}
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentStore &Store;
|
|
|
|
};
|
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
struct CodeActionHandler : Handler {
|
|
|
|
CodeActionHandler(JSONOutput &Output, ASTManager &AST)
|
|
|
|
: Handler(Output), AST(AST) {}
|
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTManager *
|
|
|
|
};
|
|
|
|
|
2017-04-04 17:46:39 +08:00
|
|
|
struct CompletionHandler : Handler {
|
|
|
|
CompletionHandler(JSONOutput &Output, ASTManager &AST)
|
|
|
|
: Handler(Output), AST(AST) {}
|
|
|
|
|
|
|
|
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTManager *
|
|
|
|
};
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|