microsoft / azure-pipelines-language-server

A language server for Azure Pipelines YAML
38 stars 26 forks source link

language server crashs when typing json like yaml `{ }` #167

Closed ChristopherHX closed 2 months ago

ChristopherHX commented 2 months ago

Version: 1.237.0-pr-574-c4a655e the unreleased update downloaded here https://github.com/microsoft/azure-pipelines-vscode/pull/574 under GitHub Actions

YAML

variables:
- template: ./v1.yaml
stages:
- stage:
  variables:
  - template: ./v1.yaml
    parameters:
      test: me
  jobs:
  - job:
    variables:
    - template: ./v1.yaml
      parameters:
        test: me
    # Everything before typing the following line works without crash
    - {  }

Crash

/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1981
    return node.key.kind === Yaml.Kind.SCALAR &&
                ^

TypeError: Cannot read properties of undefined (reading 'key')
    at isCompileTimeExpression (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1981:17)
    at addItemsToArrayNode (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1922:48)
    at recursivelyBuildAst (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1833:13)
    at recursivelyBuildAst (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1825:48)
    at addPropertiesToObjectNode (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1900:30)
    at recursivelyBuildAst (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1813:13)
    at addItemsToArrayNode (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1972:28)
    at recursivelyBuildAst (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1833:13)
    at recursivelyBuildAst (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1825:48)
    at addPropertiesToObjectNode (/home/user/.vscode-oss/extensions/ms-azure-devops.azure-pipelines-1.237.0-pr-574-c4a655e/dist/server.js:1900:30)

Node.js v20.9.0
[Error - 17:52:00] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read properties of undefined (reading 'key')
  Code: -32603 
[Error - 17:52:00] Connection to server got closed. Server will not be restarted.

I wanted to see how intellisense works in that case inside this extension and noticed that the language server has gone away

DmitriiBobreshev commented 2 months ago

Hi @ChristopherHX, thank you for the feedback, we'll try to improve error handling and fix the problem once we'll have enough time!

winstliu commented 2 months ago

@ChristopherHX would that be valid YAML? Put another way, if the language server didn't crash, what would you have written?

(The language server shouldn't crash regardless so this is definitely a bug, just trying to understand what the intended outcome would have been.)

ChristopherHX commented 2 months ago

Hi, yes that sample is valid YAML, but not yet a valid pipeline.

I'm normally not writing this kind of syntax like most other people, if the extension would just have been silent about this part of the file this issue wouldn't exist.

Looks like a regression of changes to the language server to tollerate expressions for me.

This is how it would look if it becomes a valid pipeline

variables:
- template: ./v1.yaml
stages:
- stage:
  variables:
  - template: ./v1.yaml
    parameters:
      test: me
  jobs:
  - job:
    variables:
    - template: ./v1.yaml
      parameters:
        test: me
    # Everything before typing the following line works without crash
    - { name: myvar, value: yes this is yaml  }

Pipeline Preview from my test repo after ADO validated the pipeline and has processed it

variables:
- name: vara
  value: varb
stages:
- stage: ''
  variables:
  - name: vara
    value: varb
  jobs:
  - job: ''
    variables:
    - name: vara
      value: varb
    - name: myvar
      value: yes this is yaml

I'm researching in a free time project how to implement autocomplete from scratch for azure pipelines incl. expressions and came across this crash while looking how it works here. Take the time you need.

ChristopherHX commented 2 months ago

Note: the valid pipeline doesn't crash this plugin, you just can't type it without killing it.