Skip to content

TypeScript language server

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

Preconditions:

  1. Create workspace from the Node stack with nodejs-hello-world project.
  2. Enable TypeScript language server in the Installers tab and start the workspace.
  3. Create “Greeter.ts” file with content:
import {Print} from './testPrint'

class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
    
     testPrint(): void {
        const printVar = new Print();
        printVar.print("test print");
    }
}

let greeter = new Greeter("world");
  1. Create "testPrint.ts" with content:
let name: string;
export class Print {

print (setVAlue: string): void 

{
    name = setVAlue;
    console.log('<<:'+ name);
}     
    
}

Testing process

  • Language server initialization
  1. From the project open "Greeter.ts" file.
  2. Check Finished language servers initialization, file path '/nodejs-hello-world/Greeter.ts' message in the dev-machine console.
  • Autocomplete feature
  1. Open "Greeter.ts" file.
  2. Add empty line after the code and type greeter.. Sent Ctrl+Space. Make sure that greet function and greeting field are present in the proposal panel.
  3. Delete the added line.
  • Find definition feature
  1. Open "Greeter.ts" file.
  2. Set cursor to 14:20 position and invoke Assistant -> Find Definition. The "testPrint.ts" file should be opened and print function should be selected.
  3. Close the "testPrint.ts" file. Repeat previous step using F4 key instead of Assistant -> Find Definition invocation.
  • Code validation feature, Comment line
  1. Open "Greeter.ts" file.
  2. Move cursor in 3:2 position.
  3. Add space into keyword class like: c lass. Make sure that error markers have appeared. Click on first marker and check the message like: Cannot find name 'lass'..
  4. Restore content. Error marker should disappear.
  5. Move cursor in line 1 position and comment this line by Ctrl+/ buttons.
  6. Check that text in line 1 was changed from import {Print} from './testPrint' to //import {Print} from './testPrint'.
  7. Uncomment this line by Ctrl+/ buttons.
  • Format code feature
  1. Open "testPrint.ts" file.
  2. Start Format option from context menu;
  3. Check that the file content after formatting was changed to:
let name: string;
export class Print {

    print(setVAlue: string): void {
        name = setVAlue;
        console.log('<<:' + name);
    }

}

Rename

  1. Open "Greeter.ts" file.
  2. Select printVar 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.

Find References

  1. Open "Greeter.ts" file.
  2. Move mouse pointer on position 4:12.
  3. Start Find References feature by pressing Alt+F7 buttons or from Assistant menu.
  4. Check that Find References panel is opened with /nodejs-hello-world/Greeter.ts From:4:5 To:4:13 result in it.

Signature Help

  1. Open "Greeter.ts" file.
  2. Add empty line after the code and type greeter.testPrint.
  3. Type '(' symbol and wait for hover popup with testPrint(): void text.
  4. Delete added line.

Go To Symbol

  1. Open "Greeter.ts" file.
  2. Start Go To Symbol feature by Ctrl+F12 buttons or from Assistant menu.
  3. Wait for Go To Symbol form is opened with next lines:
"Greeter" symbols(9)
greeter
Greeter
constructor
greet
greeting
testPrint
printVar
Print
  1. Click on any of them and check that it correctly selected in file.

Find Project Symbol

  1. Open "Greeter.ts" file.
  2. Start Find Project Symbol feature by Alt+N buttons or from Assistant menu.
  3. Type print in Find Project Symbol form input.
  4. Wait for testPrint /nodejs-hello-world/Greeter.ts line.
  5. Click on it and check that it correctly selected in file.