Language Server: false positive "cannot find declaration for job reference"

Hello again! This isn’t a big deal but I figured it was worth reporting. When a job requires a previous job using matrix parameters to complete, the language server is returning some errors. I tested this using both enum and string types with the same result.

image

This passes circleci config validate and runs perfectly fine.

$ circleci config validate
Config file at .circleci/config.yml is valid.

.circleci/config.yml:

version: 2.1

jobs:
  build:
    docker:
      - image: cimg/base:stable
    parameters:
      env-name:
        type: string
        default: "dev"
    steps:
      - run: echo "hello world! we are in the << parameters.env-name >> environment"
  test:
    docker:
      - image: cimg/base:stable
    parameters:
      env-name:
        type: string
        default: "dev"
    steps:
      - run: echo "hello world! it's time to test our code"

workflows:
  pr-pipeline:
    jobs:
      - build:
          name: build-<< matrix.env-name >>
          matrix:
            parameters:
              env-name:
                - dev
                - qa
                - prod
      - test:
          requires:
            - build-dev
            - build-qa
            - build-prod

Circle CI Language Server log, but it doens’t look too interesting to me unfortunately.

No port defined: the server will find a free port

Server started on port 42993, version 0.6.0
   JSON Schema: /home/kherring/.local/share/CircleCI-language-server/schema.json
New client connection

Called method: initialize

Called method: initialized
Called method: textDocument/didOpen

Called method: workspace/didChangeConfiguration
Called method: workspace/executeCommand

Called method: textDocument/documentSymbol

Called method: textDocument/codeAction
Called method: textDocument/documentSymbol

Called method: textDocument/semanticTokens/full

Called method: workspace/executeCommand

Called method: textDocument/codeAction

Called method: textDocument/codeAction

Called method: textDocument/codeAction

Called method: textDocument/codeAction

I think that is to be expected as "circleci config validate is designed to

You can avoid pushing additional commits to test your .circleci/config.yml and 
confirm that your file is free of syntax errors, YAML linting issues, etc. by using 
the CircleCI CLI to validate your configuration locally.

So is looking at the basic YAML structure of your config,yml file, while the 3 tasks it is reporting as missing are only fully defined at runtime as you have made them dynamic in nature.

In many ways, you are showing a limitation of the current documentation for the validator.

I’m hoping the language server could detect that this uses dynamic config and possible validate it fully, or change it to INFO instead of error. As is, the errors make it difficult to know when we’ve introduced a new error because it’s always in an error state.

For most users a ‘Cannot find’ error would be the correct response as the use of matrix based parameters is an advanced feature and so one used by only a few users.

The real issue/problem is that there is no real way to fully validate a config.yml file unless that file is fully processed with in the full runtime environment that can provide the full context in which the script is to be run, this is not something that a local CLI tool can do.