Changeset ebe0f0d


Ignore:
Timestamp:
Apr 6, 2020, 1:28:00 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Added basic language server which now properly communicates with the client

Location:
tools
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • tools/langserver/src/json.hpp

    rb52abe0 rebe0f0d  
    44
    55namespace json {
    6       auto parse(const std::vector<char> & buff) {
     6      static inline auto parse(const std::vector<char> & buff) {
    77            return nlohmann::json::parse(buff.begin(), buff.end());
    88      }
  • tools/langserver/src/main.cpp

    rb52abe0 rebe0f0d  
     1#include <cstdio>
     2
    13#include <iostream>
    24#include <string>
    35#include <vector>
    46
     7#include <unistd.h>
     8
    59#include "json.hpp"
    610#include "log.hpp"
     11#include "server.hpp"
    712
    813static void request(std::vector<char> & buf);
     14static void reply(const json::obj & );
    915
    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         }
     16json::obj noop( const json::obj & ) {
     17        return {};
    2018}
    2119
    2220std::unordered_map<std::string, json::obj (*)( const json::obj & )> actions {
    23         { "initialize", server::init }
     21        { "initialize", server::init },
     22        { "initialized", noop }
    2423};
    2524
     
    3231                log() << "\t- " << argv[i] << std::endl;
    3332        }
     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;
    3446
    3547        std::vector<char> buffer;
     
    5365                                response["error"] = error;
    5466                        }
    55                         log() << "Responding with : " << response.dump(4) << std::endl;
    56                         std::cout << response.dump() << std::endl;
     67
     68                        reply(response);
    5769                }
    5870                else {
     
    8698        buffer.resize( len + 2 );
    8799        std::cin.read(buffer.data(), buffer.size());
     100
     101        for(char c : buffer) {
     102                log() << c;
     103        }
     104        log() << std::endl;
    88105        return;
    89106}
     107
     108static 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
     5namespace server {
     6        json::obj init(const json::obj & );
     7};
  • tools/vscode/uwaterloo.cforall-0.1.0/client/main.js

    rb52abe0 rebe0f0d  
    2323        // Otherwise the run options are used
    2424        let serverOptions = {
    25                 run: { command: 'cfa-ls', transport: vscode_lc.TransportKind.ipc },
     25                run: { command: 'cfa-ls', transport: vscode_lc.TransportKind.stdio },
    2626                debug: {
    2727                        command: 'cfa-ls',
    28                         transport: vscode_lc.TransportKind.ipc,
     28                        transport: vscode_lc.TransportKind.stdio,
    2929                        options: debugOptions
    3030                }
     
    3232
    3333        // Options to control the language client
     34        let selector = [{ scheme: 'file', language: 'cforall' }];
    3435        let clientOptions = {
    35                 // Register the server for plain text documents
    36                 documentSelector: [{ scheme: 'file', language: 'cforall' }]
     36                // Register the server for cforall documents
     37                documentSelector: selector
    3738        };
    3839
    3940        // Create the language client and start the client.
    4041        client = new vscode_lc.LanguageClient(
    41                 'CforallServer',
     42                'cforall',
    4243                'Cforall Language Server',
    4344                serverOptions,
  • tools/vscode/uwaterloo.cforall-0.1.0/package.json

    rb52abe0 rebe0f0d  
    4343                                "path": "./syntaxes/cfa.tmLanguage.json"
    4444                        }
    45                 ]
    46         },
    47         "configuration": {
    48                 "type": "object",
    49                 "title": "Example configuration",
    50                 "properties": {
    51                         "languageServerExample.maxNumberOfProblems": {
    52                                 "scope": "resource",
    53                                 "type": "number",
    54                                 "default": 100,
    55                                 "description": "Controls the maximum number of problems produced by the server."
     45                ],
     46                "configuration": {
     47                        "type": "object",
     48                        "title": "Example configuration",
     49                        "properties": {
     50                                "cforall.maxNumberOfProblems": {
     51                                        "scope": "resource",
     52                                        "type": "number",
     53                                        "default": 100,
     54                                        "description": "Controls the maximum number of problems produced by the server."
     55                                },
     56                                "cforall.trace.server": {
     57                                        "scope": "window",
     58                                        "type": "string",
     59                                        "enum": [
     60                                                "off",
     61                                                "messages",
     62                                                "verbose"
     63                                        ],
     64                                        "default": "off",
     65                                        "description": "Traces the communication between VS Code and the language server."
     66                                }
    5667                        }
    5768                }
Note: See TracChangeset for help on using the changeset viewer.