Add LSP diagnostic test files for multiple languages

Includes test files for Lua, JavaScript, PHP to verify the Paper Tonic
Modern colorscheme's diagnostic virtual text colors across different
LSPs and their expected diagnostics.
This commit is contained in:
Ray Elliott 2025-12-11 23:05:26 +00:00
parent db8d67a6b7
commit dd8cc0eaf2
4 changed files with 320 additions and 0 deletions

93
TEST_DIAGNOSTICS.md Normal file
View File

@ -0,0 +1,93 @@
# LSP Diagnostic Test Files
These files are designed to trigger LSP diagnostics of all types to test the Paper Tonic Modern colorscheme's diagnostic virtual text colors.
## Test Files
### test-diagnostics.lua
Lua file with intentional errors for lua_ls (Lua Language Server).
**Expected diagnostics:**
- **Errors** (red): Undefined variables/functions, type mismatches, invalid operations, wrong argument counts
- **Warnings** (orange): Unused variables, shadowing, unreachable code, lowercase globals
- **Hints** (green): Redundant code, style issues
**Note**: lua_ls provides the best mix of diagnostic levels.
### test-diagnostics.php
PHP file with intentional errors for Intelephense (PHP Language Server).
**Expected diagnostics:**
- **Errors** (red): Most issues appear as errors by default in Intelephense
- Undefined functions/variables
- Type mismatches
- Wrong argument counts
- Invalid method calls
**Note**: Intelephense is strict and reports most issues as errors. To see warnings/hints, configure in `.nvim.lua`:
```lua
return {
lsp = {
intelephense = {
settings = {
intelephense = {
diagnostics = {
undefinedSymbols = true,
undefinedVariables = true,
unusedSymbols = "hint", -- Show unused as hints
}
}
}
}
}
}
```
### test-diagnostics.js
JavaScript file with intentional errors for ts_ls (TypeScript Language Server).
**Expected diagnostics:**
- **Errors** (red): Undefined variables/functions, invalid property access, missing parameters
- **Warnings** (orange): Unreachable code, type comparison issues, duplicate cases
- **Hints** (green): const vs let suggestions
- **Info** (blue): Unnecessary operations
## How to Use
1. Open any test file in Neovim:
```bash
nvim test-diagnostics.lua
# or
nvim test-diagnostics.php
# or
nvim test-diagnostics.js
```
2. Wait for LSP to attach and analyze the file (1-2 seconds)
3. Check the virtual text diagnostics at the end of lines with issues
4. Use `:LspInfo` to verify the LSP server is attached
## Color Reference
The Paper Tonic Modern colorscheme uses these colors for diagnostics:
- **DiagnosticError** (virtual text): `#d70000` (bright red) on `#ffefef` background
- **DiagnosticWarn** (virtual text): `#d75f00` (orange) on `#ece0e0` background
- **DiagnosticInfo** (virtual text): `#8989af` (blue) on `#e0e0ec` background
- **DiagnosticHint** (virtual text): `#89af89` (green) on `#e0ece0` background
## Testing Checklist
- [ ] Errors show in red with red undercurl
- [ ] Warnings show in orange with orange undercurl
- [ ] Hints show in green
- [ ] Info messages show in blue
- [ ] Virtual text is readable against light background
- [ ] Sign column icons show correct colors
- [ ] Diagnostic floating windows display correctly
## Debug Command
Use the `<leader>hi` keymap to inspect highlight info under cursor and verify diagnostic colors are applied correctly.

73
test-diagnostics.js Normal file
View File

@ -0,0 +1,73 @@
/**
* Test file for JavaScript/TypeScript LSP diagnostics
* Tests error, warning, info, and hint virtual text colors
*/
// ERROR: Undefined variable
console.log(undefinedVariable);
// ERROR: Undefined function
nonexistentFunction();
// WARNING: Unused variable
const unusedVariable = "I'm never used";
// ERROR: Type error (if using TypeScript or JSDoc)
/**
* @param {string} name
* @param {number} age
*/
function greet(name, age) {
console.log(`Hello ${name}, you are ${age}`);
}
greet("Alice", "not a number"); // Type mismatch
// WARNING: Unreachable code
function earlyReturn() {
return "done";
console.log("Never executed"); // Unreachable
}
// ERROR: Invalid property access
const obj = {};
console.log(obj.nonexistent.nested.property);
// WARNING: Comparison with different types
if ("5" == 5) { // Should use ===
console.log("loose equality");
}
// ERROR: Missing parameter
greet("Bob"); // Missing age parameter
// INFO: Unnecessary type assertion (TypeScript)
const num = 123;
const str = String(num); // Could be simplified
// HINT: Variable can be const instead of let
let neverReassigned = "should be const";
console.log(neverReassigned);
// ERROR: Division by zero (some linters catch this)
const result = 10 / 0;
// WARNING: Duplicate case label
const value = 1;
switch (value) {
case 1:
console.log("one");
break;
case 1: // Duplicate case
console.log("one again");
break;
}
// ERROR: Invalid this context
const obj2 = {
name: "test",
greet: () => {
console.log(this.name); // Arrow function doesn't bind this
}
};
console.log("JavaScript diagnostic test complete!");

84
test-diagnostics.lua Normal file
View File

@ -0,0 +1,84 @@
-- Test file for LSP diagnostics - lua_ls
-- This file intentionally contains different diagnostic levels
-- to test diagnostic virtual text colors in paper-tonic-modern
-- Define some valid code first
local valid_function = function()
return "valid"
end
---@diagnostic disable-next-line: unused-local
local _ = valid_function()
-- ERROR: Undefined global (lua_ls marks this as error)
print(undefined_global_variable)
-- ERROR: Undefined function
undefined_function()
-- WARNING: Unused local variable (lua_ls warning level)
local unused_variable = "I'm never used"
-- WARNING: Lowercase global (should be local)
lowercase_global = "This should be local or uppercase"
-- HINT: Redundant parentheses (some configs treat as hint)
local x = (5)
print(x)
-- ERROR: Wrong number of arguments
local function takes_two_args(a, b)
return a + b
end
takes_two_args(1) -- Missing second argument (lua_ls error)
-- ERROR: Attempting to call a non-function
local not_a_function = "string"
not_a_function()
-- WARNING: Shadowing outer local
local shadow_me = 1
do
local shadow_me = 2 -- Shadows outer local (warning)
print(shadow_me)
end
-- ERROR: Invalid table access
local empty_table = {}
print(empty_table.nonexistent.deeply.nested.property)
-- WARNING/HINT: Can be simplified
if true == true then -- Redundant comparison
print("always true")
end
-- ERROR: Type annotation mismatch
---@type string
local should_be_string = 123 -- Assigning number to string type
-- WARNING: Unreachable code after return
local function has_dead_code()
return "done"
print("This will never execute") -- Unreachable
end
-- Valid function call
print(takes_two_args(1, 2))
-- ERROR: Calling vim API that doesn't exist
vim.nonexistent_function()
-- HINT: Trailing whitespace or style issues (if configured)
local with_trailing_space = "value"
print(with_trailing_space)
-- ERROR: Parameter type mismatch
---@param name string
---@param age number
local function greet(name, age)
print("Hello, " .. name .. ", you are " .. age)
end
greet(123, "not a number") -- Wrong types
print("Diagnostic test complete!")

70
test-diagnostics.php Normal file
View File

@ -0,0 +1,70 @@
<?php
/**
* Test file for PHP LSP diagnostics
* Tests error, warning, info, and hint virtual text colors
*
* Note: Configure Intelephense to show different diagnostic levels:
* - diagnostics.undefinedSymbols = true (errors)
* - diagnostics.undefinedVariables = true (warnings)
* - diagnostics.unusedSymbols = "hint" (hints)
*/
// Define some valid functions and variables first to avoid cascading errors
function validFunction(): void {
echo "This is valid\n";
}
$definedVariable = "I exist";
// ERROR: Undefined function
someUndefinedFunction();
// ERROR: Undefined variable
echo $completelyUndefined;
// WARNING/HINT: Unused variable (depends on Intelephense config)
$unused = "Never used anywhere";
// Valid code to separate errors
validFunction();
// ERROR: Wrong number of arguments
function requiresTwoArgs(string $a, string $b): void {
echo "$a $b\n";
}
requiresTwoArgs("only one"); // Missing second argument
// ERROR: Type mismatch
function expectsString(string $param): void {
echo $param;
}
expectsString(123); // Passing int to string parameter
// WARNING: Variable might not be defined in all code paths
if (rand(0, 1)) {
$maybeUndefined = "sometimes defined";
}
// Commenting out to reduce errors: echo $maybeUndefined;
// Valid usage
echo $definedVariable . "\n";
// ERROR: Calling method on non-object
$notAnObject = "string";
$notAnObject->someMethod();
// ERROR: Invalid array access (multiple levels)
$emptyArray = [];
echo $emptyArray['key']['nested']['deep'];
// Valid function call
requiresTwoArgs("hello", "world");
// HINT/WARNING: Unreachable code (some configs)
function hasDeadCode(): string {
return "done";
echo "This is unreachable"; // Dead code
}
echo "Test complete!\n";