vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

add support for @intelephense-ignore-line and @intelephense-ignore-next-line

Open kaioker opened this issue 2 years ago • 4 comments

sometimes a percieved error is not actually an error. take this example: if(class_exists("THING_1")) THING_1::run(); this causes Undefined type 'THING_1'.intelephense(1009)

proposing this as an option: if(class_exists("THING_1")) THING_1::run(); // @intelephense-ignore-line

here is an example of a way to ignore certain lines as implemented into intelephense (PHP language server) extension for coc.nvim: https://github.com/yaegassy/coc-intelephense/commit/e234629636a4d6e5c277cf6bfa8fc35f842300d5

kaioker avatar Feb 10 '23 00:02 kaioker

@kaioker Thanks for referring to my plugin (extension) for Vim/Neovim.

The PR for this function also includes a DEMO (mp4) as an example of how it works, so we will post that as well.

yaegassy avatar Feb 10 '23 01:02 yaegassy

@yaegassy how similar is the vscode branch of intelephense compared to the coc-intelephense branch? any chance you could make the same merge request here too? things tend to move faster when theres a merge request. i attempted to do it myself, but being a php developer, not typescript, i am a bit lost as to what actually needs to be done.

kaioker avatar Feb 10 '23 18:02 kaioker

If we add an implementation in the form of handleDiagnostics: ... here, it would be a feature that works the same way in vscode-intelephense.

https://github.com/bmewburn/vscode-intelephense/blob/d9f9da554e3441cfcc5139f63765f3e60e31acf8/src/middleware.ts#L84-L102

However, I would like to see this addressed on the intelephense language server side, not on the extension side.

yaegassy avatar Feb 14 '23 01:02 yaegassy

Found a solution in the source:

/**
 * @disregard P1009 Undefined type
 */
SomeNonExistingClass::whatever(); // this works

// Resetted from here
SomeNonExistingClass::whatever(); // this will show an error

// @disregard P1009 Undefined type
SomeNonExistingClass::whatever(); // this also won't work

// and neither the next
SomeNonExistingClass::whatever(); // @disregard P1009 Undefined type

This works for single code lines and entire code blocks. So with 'if' and 'else(if)' structures you need to place it above the 'if'-line. In this case it will also work for the 'else(if)' case(s). When using a 'switch' you place it above the 'switch' line and it will work for all 'case'-lines.

nullester avatar Dec 18 '23 14:12 nullester

An /** @disregard [OPTIONAL_CODE] [OPTION_DESCRIPTION] */ annotation has been added as a way to suppress diagnostics.

bmewburn avatar Apr 11 '24 21:04 bmewburn

@bmewburn Question: How do I @disregard this Player return type in the following case? I know the type is correct, the false positive diagnostic is caused by a third party package (https://github.com/barryvdh/laravel-ide-helper/issues/1442)

image

Expected type 'App\Models\Player'. Found 'Illuminate\Cache\TCacheValue'.intelephense(P1006)

jhm-ciberman avatar May 24 '24 15:05 jhm-ciberman