diff --git a/integration-test/diagnostics.test.ts b/integration-test/diagnostics.test.ts index 5eb6558..f7a3d64 100644 --- a/integration-test/diagnostics.test.ts +++ b/integration-test/diagnostics.test.ts @@ -14,6 +14,16 @@ suite('Diagnostics', () => { }, ]) }) + + test('error diagnostics', async () => { + await testDiagnostics('error.sksl', [ + { + message: "'main' must return: 'vec4', 'float4', or 'half4'", + range: toRange(3, 0, 3, 11), + severity: vscode.DiagnosticSeverity.Error, + }, + ]) + }) }) async function testDiagnostics(name: string, expected: vscode.Diagnostic[]) { diff --git a/integration-test/fixtures/error.sksl b/integration-test/fixtures/error.sksl new file mode 100644 index 0000000..d7d0e32 --- /dev/null +++ b/integration-test/fixtures/error.sksl @@ -0,0 +1,4 @@ +// kind=shader +// δΈ­ζ–‡ +// πŸ˜‹πŸ˜‹ +void main() {} diff --git a/src/offset-position-converter.ts b/src/offset-position-converter.ts index 3ae5eb7..71ff57a 100644 --- a/src/offset-position-converter.ts +++ b/src/offset-position-converter.ts @@ -10,7 +10,8 @@ export class OffsetPositionConverter { let index = 0 let prev = ' ' - for (const c of content) { + for (let i = 0; i < content.length; ++i) { + const c = content.charAt(i) switch (c) { case '\n': if (prev == '\n') {