Skip to content

How to Use: Code Completion: Settings When a jsconfig.json Already Exists in the Workspace

Overview

To use the code completion feature with "Pleasanter Code Assist" 1.4.0 or later, the following setup is required.

  1. Installing the type definition files
  2. Creating jsconfig.json and adding references to the type definition files

These are normally performed automatically by Pleasanter Code Assist. However, if a jsconfig.json already exists in the workspace, Pleasanter Code Assist creates the type definition files but does not add references to them in the existing jsconfig.json. This is because overwriting the existing jsconfig.json could lose the target files, JavaScript version, libraries, paths and other settings configured by the user.

Type definition files required for code completion

・.pleasanter/pleasanter-script.d.ts
・.pleasanter/pleasanter-server-script.d.ts

In this case, you need to add the references to the corresponding type definition files to jsconfig.json manually, while keeping your existing settings. This page explains those steps.

Files to Check

The files to check and the type definitions to reference are as follows. The relative path from each of the four target folders to .pleasanter is ../../.pleasanter in every case.

Location of jsconfig.json Type definition to add
sites/scripts/jsconfig.json ../../.pleasanter/pleasanter-script.d.ts
extensions/scripts/jsconfig.json ../../.pleasanter/pleasanter-script.d.ts
sites/serverscripts/jsconfig.json ../../.pleasanter/pleasanter-server-script.d.ts
extensions/serverscripts/jsconfig.json ../../.pleasanter/pleasanter-server-script.d.ts

When the Existing jsconfig.json Has an include

Do not delete the existing content of include; add the type definition file to the end of the array. The following is an example for the case where sites/scripts/jsconfig.json has the content below.

{
    "compilerOptions": {
        "target": "ES2020"
    },
    "include": [
        "src/**/*.js"
    ]
}

Add the relative path to the type definition file for Scripts, "../../.pleasanter/pleasanter-script.d.ts", to "include".

{
    "compilerOptions": {
        "target": "ES2020"
    },
    "include": [
        "src/**/*.js",
        "../../.pleasanter/pleasanter-script.d.ts"
    ]
}

Do not change other items configured by the user, such as target. The path to add is the same for extensions/scripts.

For Server Scripts, add the relative path to the type definition file for Server Scripts, "../../.pleasanter/pleasanter-server-script.d.ts", to "include".

{
    "compilerOptions": {
        "target": "ES2020"
    },
    "include": [
        "src/**/*.js",
        "../../.pleasanter/pleasanter-server-script.d.ts"
    ]
}

When the Existing jsconfig.json Has No include

If the existing jsconfig.json has no include, add both the JavaScript files and the type definition file. If you specify only the type definition file, the JavaScript files in the same folder may be excluded from the project.

An example for Scripts is as follows.

{
    "compilerOptions": {
        "allowJs": true,
        "checkJs": false,
        "target": "ES2022",
        "lib": [
            "ES2022",
            "DOM"
        ]
    },
    "include": [
        "**/*.js",
        "../../.pleasanter/pleasanter-script.d.ts"
    ]
}

An example for Server Scripts is as follows. Server Scripts do not use the DOM of the browser, so DOM is not added to lib.

{
    "compilerOptions": {
        "allowJs": true,
        "checkJs": false,
        "target": "ES2022",
        "lib": [
            "ES2022"
        ]
    },
    "include": [
        "**/*.js",
        "../../.pleasanter/pleasanter-server-script.d.ts"
    ]
}

The above are examples for the case where there are almost no existing settings. If compilerOptions already exists, do not delete the existing settings; first add only the type definition to include.

Because the type definitions of Pleasanter Code Assist are loaded directly from include, you do not need to change the existing types just to enable code completion. Since the user may be using @types/node or similar, do not change the existing types to an empty array.

When the Existing jsconfig.json Uses files

If the existing jsconfig.json specifies the target files one by one with files instead of include, add the corresponding type definition file to files.

{
    "files": [
        "sample.js",
        "../../.pleasanter/pleasanter-script.d.ts"
    ]
}

In this case, adding */.js to include could bring JavaScript files that the user did not intend into scope. Give priority to a method that keeps the existing files.

Checking After the Change

Once you have finished changing the settings, check that code completion works correctly with the following steps.

  1. Edit jsconfig.json and save it.
  2. Open the target script file.
  3. Type $p. in a Script, or items. or context. in a Server Script.
  4. Check that the completion candidates and descriptions are displayed.

If code completion does not appear right away, run "TypeScript: Restart TS Server" from the command palette of Visual Studio Code (Ctrl + Shift + P).

If it still does not appear, check the relative path in include or files, syntax errors in the JSON, and whether .pleasanter is excluded by exclude.

Supported Versions

Supported Version Description
Pleasanter 1.5.8.0 and later Code completion feature added