vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Intellisense configuration through custom tasks

Open MKHenson opened this issue 10 years ago • 8 comments

Hi all

Is there a way to sync intellisense with custom build tasks? I am working in a TypeScript project, and as I understand it, Code reads the tsconfig.json to do its intellisense (among other things). However my compilation is done through a gulp task. This task reports errors for me and I've setup a problem matcher to catch those. The problem comes in however when there seems to be a mismatch between the service generating intellisense and the build process I am using. I can build my project for example (using the gulp task) and no errors will show up - however I can go to a file and see red squiggles under things that have no errors. Are there ways I can sync the intellisense with my tasks?

This is my tasks json:

{
    "version": "0.1.0",
    "command": "gulp",
    "isShellCommand": true,
    "args": [
         "--no-color"
    ],
    "tasks": [
    {
        "taskName": "build-all",
        "isBuildCommand": true,
        "showOutput": "silent",
        "problemMatcher": {
            "fileLocation": ["relative", "${workspaceRoot}"],
            "pattern": {
                "regexp": "^(.*)\\((.*),(.*)\\):\\s(error|warning)\\s(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        }
    }]
}

My Code version is 0.10.8

Thanks for a great project, and look forward to future updates :)

MKHenson avatar Mar 06 '16 13:03 MKHenson

@MKHenson which version of tsc do you use for your gulp compliation. I suspect that there is a version mismatch wich results in different squiggles. You can control the TS version used by VSCode using the typescript.tsdk setting.

dbaeumer avatar Mar 09 '16 14:03 dbaeumer

Hi @dbaeumer

I have only got one version of Typescript installed, which is 1.8.2. I installed it globally using npm. My typescript.tsdk setting is set to null (so i presume it uses the default tsc command used in the npm module folder).

In my source files I have a main.ts file which includes all references to definitions.

(main.ts)
/// <reference path="./definitions/required/node.d.ts" />
/// <reference path="./definitions/required/express.d.ts" />
/// <reference path="./definitions/required/bcrypt.d.ts" />
etc...

Main.ts should be part of the compilation as I understand it. So even though these modules are defined and referenced in the definition files, the editor seems to complain about them not existing - and yet compilation is fine. Is this maybe because the editor only reads references in open files? If I put those reference paths in every file then the squiggles go away. The problem still exists even if I specify the .files property in the tsconfig.json (I thought it might be an ordering problem - i.e. that main.ts is not loaded first and so files dont see the definitions in order)

I've attached a picture to show what I mean. problem

Here is my tsconfig file

{
  "compilerOptions": {
    "module": "commonjs",
    "removeComments": false,
    "noEmitOnError": true,
    "declaration": false,
    "sourceMap": false,
    "preserveConstEnums": true,
    "target": "es5",
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "outDir": "dist"
  }
}

And here is my task file:

{
    "version": "0.1.0",
    "command": "gulp",
    "isShellCommand": true,
    "args": [
         "--no-color"
    ],
    "tasks": [
        {
            "taskName": "build-all",
            "isBuildCommand": true,
            "showOutput": "always",
            "problemMatcher": {
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*)\\((.*),(.*)\\):\\s(error|warning)\\s(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

Gulp file:

var gulp = require('gulp');
var ts = require('gulp-typescript');
var outDir = "dist";

// Builds each of the ts files into JS files in the output folder
gulp.task('ts-code', function() {
    return gulp.src(['src/**/*.ts', 'src/**/*.json'], { base: "src" })
        .pipe(ts({
            "module": "commonjs",
            "removeComments": false,
            "noEmitOnError": true,
            "declaration": false,
            "sourceMap": false,
            "preserveConstEnums": true,
            "target": "es5",
            "noImplicitAny": false
            }))
        .pipe(gulp.dest(outDir));
});

gulp.task('build-all', ['ts-code']);

MKHenson avatar Mar 10 '16 09:03 MKHenson

@MKHenson no, VSCode doesn't use the globally install tsc. It ships with its own version. If you want to use the globally installed version of tsc then you need to set the typescript.tsdk setting.

However I think the problem is a configuration one. The gulp-typescript compiler is configured on the src folder. Where does your tsconfig.json file sit. And were do the typings sit (e.g. the node.d.ts file for the typings for 'http').

Could you share your project. That would ease tracking down the problem.

dbaeumer avatar Mar 14 '16 12:03 dbaeumer

Hi @dbaeumer, I can't seem to isolate the problem... Sometimes it works after a while and other times not. I can't figure out what the deciding factors are :/

If I can get a repeatable set of steps then I'll reopen the issue and explain in more detail. But thanks for your response.

MKHenson avatar Mar 14 '16 13:03 MKHenson

@MKHenson if you can share your project I can have a quick look at the setup. May be I see something.

dbaeumer avatar Mar 15 '16 08:03 dbaeumer

Sure thing, you can view it from here

MKHenson avatar Mar 15 '16 09:03 MKHenson

OK. The problem is your tsconfig.json files section. This only list three files which makes the ts project only consist of these three files and the files they reference using /// references. All other files are treated as separate virtual projects. So if you for example open users.ts it will be its own TS project. It will not be together with the project defined by your tsconfig.json file.

I would recommend to remove the files section and to exclude the dist folder instead.

The reason why your gulp is working is that you in that setup pipe all src/*.ts files into the compiler.

dbaeumer avatar Mar 24 '16 11:03 dbaeumer

Ah I see, thanks @dbaeumer

MKHenson avatar Mar 24 '16 11:03 MKHenson