microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.05k stars 29.21k forks source link

Problems/Diagnostics does not show "Code" #44017

Closed tboby closed 6 years ago

tboby commented 6 years ago

Issue Type

Bug? All other diagnostic fields are shown

Description

  1. Generate diagnostics
  2. Right click copy shows: file: 'file:///f%3A/Games/Steam/steamapps/common/Stellaris/mod/newhorizons/common/megastructures/03_think_tank.txt' severity: 'Warning' message: 'Localisation key think_tank_0_CONSTRUCTION_INFO_DELAYED is not defined for English' at: '9,1' source: '' code: 'CW000'
  3. UI shows: image

I would expect the error code to be shown to users. How else can we let users filter diagnostics or look up further details?

VS Code Info

VS Code version: Code 1.20.1 (f88bbf9137d24d36d968ea6b2911786bfe103002, 2018-02-13T15:34:36.336Z) OS version: Windows_NT x64 10.0.16299

System Info |Item|Value| |---|---| |CPUs|AMD FX-8370 Eight-Core Processor (8 x 4335)| |Memory (System)|7.90GB (0.95GB free)| |Process Argv|C:\Program Files\Microsoft VS Code\Code.exe| |Screen Reader|no| |VM|0%|
Extensions (12) Extension|Author (truncated)|Version ---|---|--- paradox-syntax|ada|1.0.1 tslint|eg2|1.0.28 scaffold|fir|1.0.0 Ionide-FAKE|Ion|1.2.3 Ionide-fsharp|Ion|3.16.0 Ionide-Paket|Ion|1.9.1 vscode-nuget-package-manager|jmr|1.1.6 python|ms-|2018.1.0 csharp|ms-|1.14.0 yo|sam|0.9.3 spellchecker|swy|1.2.13 cwtools-vscode|tbo|0.2.15
egamma commented 6 years ago

The diagnostic is produced by an extension and it is up to the extension to define what is shown in the message. Please report the issue against the extension that is producing this warning.

tboby commented 6 years ago

@egamma It's produced by my extension, I'm reporting a bug in how vscode handles the diagnostics I provide! If you look at 2 vs 3, 2 shows vscode is receiving my error code, 3 shows it isn't displaying it.

egamma commented 6 years ago

@tboby sorry didn´t notice that it is your extension. However the API is clear that code is an internal identifier that isn´t exposed to the user. From the API

/**
         * A code or identifier for this diagnostics. Will not be surfaced
         * to the user, but should be used for later processing, e.g. when
         * providing [code actions](#CodeActionContext).
         */
        code: string | number;
tboby commented 6 years ago

Hmm, interesting, that explains more than the protocol description.

/**
     * The diagnostic's code. Can be omitted.
     */
    code?: number | string;

The LSP doesn't really define "code". That API seems to state it's an "identifier", does this mean vscode assumes it's a unique identifier for that diagnostic? Or a set of diagnostics with the same meaning?

Sorry, one downside of the LSP is that I don't touch vscode APIs, so didn't think to look there! The Language Extension Guidelines don't go into this much detail.

egamma commented 6 years ago

@tboby when implementing a Language Server then the LSP protocol is what matters and you should not have to depend on the API of the Language Server host.

The LSP protocol spec is correct, based on this specification you cannot assume that the code is a user visible concept that is shown by all the LS hosts. The LSP support for VS Code has decided to not to show code to the user and this conforms with the LSP spec.

tboby commented 6 years ago

@egamma I raised this in the LSP repo, #409. The protocol has been amended to read:

    /**
     * The diagnostic's code, which might appear in the user interface.
     */
    code?: number | string;

Obviously, VS Code is still compliant.

Would surfacing the error code in some way (even if just opt-in) be an appropriate feature request?

egamma commented 6 years ago

@tboby yes this would be valid feature request. For example, one approach would be to show the error code in the hover.