Changeset ebe0f0d for tools/langserver
- Timestamp:
- Apr 6, 2020, 1:28:00 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 057298e
- Parents:
- b52abe0
- Location:
- tools/langserver/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/langserver/src/json.hpp
rb52abe0 rebe0f0d 4 4 5 5 namespace json { 6 auto parse(const std::vector<char> & buff) {6 static inline auto parse(const std::vector<char> & buff) { 7 7 return nlohmann::json::parse(buff.begin(), buff.end()); 8 8 } -
tools/langserver/src/main.cpp
rb52abe0 rebe0f0d 1 #include <cstdio> 2 1 3 #include <iostream> 2 4 #include <string> 3 5 #include <vector> 4 6 7 #include <unistd.h> 8 5 9 #include "json.hpp" 6 10 #include "log.hpp" 11 #include "server.hpp" 7 12 8 13 static void request(std::vector<char> & buf); 14 static void reply(const json::obj & ); 9 15 10 namespace server { 11 json::obj init(const json::obj & ) { 12 return { 13 { "capabilities", json::obj::array() }, 14 { "serverInfo", { 15 { "name", "Cforall Language Server" }, 16 { "version", "0.1" } 17 }} 18 }; 19 } 16 json::obj noop( const json::obj & ) { 17 return {}; 20 18 } 21 19 22 20 std::unordered_map<std::string, json::obj (*)( const json::obj & )> actions { 23 { "initialize", server::init } 21 { "initialize", server::init }, 22 { "initialized", noop } 24 23 }; 25 24 … … 32 31 log() << "\t- " << argv[i] << std::endl; 33 32 } 33 34 // std::cout.setf(std::ios::unitbuf); 35 36 // char buff[1000]; 37 // int r = 0; 38 // while(0 != (r = read(STDIN_FILENO, buff, 1000))) { 39 // for(int i = 0; i < r; i++) { 40 // log() << buff[i]; 41 // } 42 // } 43 // log() << std::endl; 44 45 // return 0; 34 46 35 47 std::vector<char> buffer; … … 53 65 response["error"] = error; 54 66 } 55 log() << "Responding with : " << response.dump(4) << std::endl; 56 std::cout << response.dump() << std::endl;67 68 reply(response); 57 69 } 58 70 else { … … 86 98 buffer.resize( len + 2 ); 87 99 std::cin.read(buffer.data(), buffer.size()); 100 101 for(char c : buffer) { 102 log() << c; 103 } 104 log() << std::endl; 88 105 return; 89 106 } 107 108 static void reply( const json::obj & response) { 109 if(response["result"].is_null()) { 110 log() << "No response needed" << std::endl; 111 return; 112 } 113 114 log() << "Responding with : " << response.dump(4) << std::endl; 115 const std::string & r = response.dump(); 116 std::cout << "Content-Length: " << r.length() << "\r\n\r\n"; 117 std::cout.flush(); 118 std::cout << r << "\r\n"; 119 std::cout.flush(); 120 } -
tools/langserver/src/server.hpp
rb52abe0 rebe0f0d 1 #pragma once 2 3 #include "json.hpp" 4 5 namespace server { 6 json::obj init(const json::obj & ); 7 };
Note: See TracChangeset
for help on using the changeset viewer.