mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
If a line or column is unknown, we internally represent it as line or column -1. When mapped from our 1-based numbering to LSP's 0-based numbering, it comes out as -2, which is out of range since LSP requires lines and columns to be >= 0. Detect this case and produce a fallback. Assisted-by: Claude via Antigravity
77 lines
2.9 KiB
Plaintext
77 lines
2.9 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/language_server/testdata/text_document/diagnostics_no_line.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/language_server/testdata/text_document/diagnostics_no_line.carbon
|
|
|
|
// An api file with an `.impl.carbon` extension gets a diagnostic about the
|
|
// file as a whole, with no line or column. Its range must not be negative.
|
|
|
|
// --- STDIN
|
|
[[@LSP-CALL:initialize:"capabilities": {}]]
|
|
[[@LSP-NOTIFY:textDocument/didOpen:
|
|
"textDocument": {"uri": "file:/test.impl.carbon", "languageId": "carbon",
|
|
"version": 1, "text": "fn F() {}"}
|
|
]]
|
|
[[@LSP-CALL:shutdown]]
|
|
[[@LSP-NOTIFY:exit]]
|
|
|
|
// --- AUTOUPDATE-SPLIT
|
|
|
|
// CHECK:STDOUT: Content-Length: 432{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 1,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": {
|
|
// CHECK:STDOUT: "capabilities": {
|
|
// CHECK:STDOUT: "declarationProvider": true,
|
|
// CHECK:STDOUT: "definitionProvider": true,
|
|
// CHECK:STDOUT: "documentFormattingProvider": true,
|
|
// CHECK:STDOUT: "documentSymbolProvider": true,
|
|
// CHECK:STDOUT: "hoverProvider": true,
|
|
// CHECK:STDOUT: "implementationProvider": true,
|
|
// CHECK:STDOUT: "positionEncoding": "utf-16",
|
|
// CHECK:STDOUT: "referencesProvider": true,
|
|
// CHECK:STDOUT: "textDocumentSync": 2,
|
|
// CHECK:STDOUT: "typeDefinitionProvider": true
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 500{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "method": "textDocument/publishDiagnostics",
|
|
// CHECK:STDOUT: "params": {
|
|
// CHECK:STDOUT: "diagnostics": [
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "message": "file extension of `.carbon` required for api",
|
|
// CHECK:STDOUT: "range": {
|
|
// CHECK:STDOUT: "end": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 0
|
|
// CHECK:STDOUT: },
|
|
// CHECK:STDOUT: "start": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: },
|
|
// CHECK:STDOUT: "severity": 1,
|
|
// CHECK:STDOUT: "source": "carbon"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: "uri": "file:///test.impl.carbon",
|
|
// CHECK:STDOUT: "version": 1
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 51{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 2,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": null
|
|
// CHECK:STDOUT: }
|