Skip to content

Clang language server

Sergey Skorik edited this page Sep 10, 2018 · 4 revisions

Preconditions:

  1. Create workspace from the C++ stack with console-cpp-simple project.
  2. Enable Clangd language server in the Installers tab and start the workspace.
  3. Create "hello.cc" file with content:
#include <iostream>
 
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}
  1. Create “iseven.h” file with content:
#ifndef VARIABLE
#define VARIABLE

int isEven(int arg);

#endif
  1. Create "iseven.cpp" with content:
                  int isEven(int x)     {
    return x % 2 ==               0;
                    }
  1. Create "hello.cpp" with content:
#include <iostream>
#include "iseven.h"

void test(int);

int main()
{
    int x   =   4;
  std::cout << "Hello World!" << std::endl;
  std::cout << isEven(x) << std::endl;
  return 0;
}

Testing process

  • Language server initialization
  1. From the project open "hello.cc" file.
  2. Check Finished language servers initialization, file path '/console-cpp-simple/hello.cc message in the dev-machine console.
  • Code validation feature, Autocomplete feature
  1. Open "hello.cc" file.
  2. Add a new line in line 6. Type std::. Make sure that error marker with expected unqualified-id message appears.
  3. Type std::cou and launch code assistant by Ctrl+Space. Select cout outstream from the proposal menu. Type << "Hello World!;" Make sure that there is no any errors.
  4. Erase std::. Make sure that error marker appears in line 6. Add using namespace std;in the line 2. 5. Make sure that there is no any errors.
  • Find definition feature
  1. Open "hello.cpp" file.
  2. Set cursor to 10:20 position and invoke Assistant -> Find Definition. The "iseven.h" file should be opened and add function should be selected.
  3. Close the "iseven.h" file. Repeat previous step using F4 key instead of Assistant -> Find Definition invocation.
  • Comment line
  1. Open "hello.cc" file.
  2. Move cursor in line 5 position and comment this line by Ctrl+/ buttons.
  3. Check that text in line 3 was changed from std::cout << "Hello World!" << std::endl; to // std::cout << "Hello World!" << std::endl;.
  4. Uncomment this line by Ctrl+/ buttons.
  • Format code feature
  1. Open "hello.cpp" file.
  2. Select all text on line 8.
  3. Start Format option from context menu in the Editor;
  4. Check that the file content after formatting selected code was changed to:
  int x = 4;
  1. Open "iseven.cpp" file.
  2. Start Format option from context menu.
  3. Check that the file content after full file formatting was changed to:
int isEven(int x) { return x % 2 == 0; }

Rename

  1. Open "hello.cpp" file.
  2. Select "x" variable.
  3. Start Rename feature by Shift+F6 or from Assistant menu.
  4. Type new variable name.
  5. Check that the variable name was changed.

Signature Help

  1. Open "hello.cpp" file.
  2. Add a new line in line 8 and type isEven.
  3. Type '(' symbol and wait for hover popup with isEven(int arg)->int text.
  4. Delete added line.