mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Implements formatting support within LSP. Current implementation performs while file formatting, we just replace file with output of Carbon::Format() https://github.com/carbon-language/carbon-lang/pull/7687 independently improves formatting so that this output is somewhat decent. Assisted-With: Gemini / Antigravity
138 lines
4.9 KiB
Plaintext
138 lines
4.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/formatting/basic.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/language_server/testdata/formatting/basic.carbon
|
|
|
|
// --- STDIN
|
|
[[@LSP-CALL:initialize:"capabilities": {}]]
|
|
[[@LSP-NOTIFY:textDocument/didOpen:
|
|
"textDocument": {"uri": "file:/unformatted.carbon", "languageId": "carbon",
|
|
"text": "fn F( ) { return ; }"}
|
|
]]
|
|
[[@LSP-CALL:textDocument/formatting:
|
|
"textDocument": {"uri": "file:/unformatted.carbon"},
|
|
"options": {"tabSize": 2, "insertSpaces": true}
|
|
]]
|
|
[[@LSP-NOTIFY:textDocument/didOpen:
|
|
"textDocument": {"uri": "file:/formatted.carbon", "languageId": "carbon",
|
|
"text": "fn F() {\n return;\n}\n"}
|
|
]]
|
|
[[@LSP-CALL:textDocument/formatting:
|
|
"textDocument": {"uri": "file:/formatted.carbon"},
|
|
"options": {"tabSize": 2, "insertSpaces": true}
|
|
]]
|
|
[[@LSP-NOTIFY:textDocument/didOpen:
|
|
"textDocument": {"uri": "file:/empty.carbon", "languageId": "carbon",
|
|
"text": ""}
|
|
]]
|
|
[[@LSP-CALL:textDocument/formatting:
|
|
"textDocument": {"uri": "file:/empty.carbon"},
|
|
"options": {"tabSize": 2, "insertSpaces": true}
|
|
]]
|
|
[[@LSP-CALL:shutdown]]
|
|
[[@LSP-NOTIFY:exit]]
|
|
|
|
// CHECK:STDOUT: Content-Length: 394{{\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: "positionEncoding": "utf-16",
|
|
// CHECK:STDOUT: "referencesProvider": true,
|
|
// CHECK:STDOUT: "textDocumentSync": 2,
|
|
// CHECK:STDOUT: "typeDefinitionProvider": true
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 151{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "method": "textDocument/publishDiagnostics",
|
|
// CHECK:STDOUT: "params": {
|
|
// CHECK:STDOUT: "diagnostics": [],
|
|
// CHECK:STDOUT: "uri": "file:///unformatted.carbon"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 284{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 2,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": [
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "newText": "fn F () {\n return;\n}\n",
|
|
// CHECK:STDOUT: "range": {
|
|
// CHECK:STDOUT: "end": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 1
|
|
// CHECK:STDOUT: },
|
|
// CHECK:STDOUT: "start": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: }Content-Length: 149{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "method": "textDocument/publishDiagnostics",
|
|
// CHECK:STDOUT: "params": {
|
|
// CHECK:STDOUT: "diagnostics": [],
|
|
// CHECK:STDOUT: "uri": "file:///formatted.carbon"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 284{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 3,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": [
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "newText": "fn F () {\n return;\n}\n",
|
|
// CHECK:STDOUT: "range": {
|
|
// CHECK:STDOUT: "end": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 4
|
|
// CHECK:STDOUT: },
|
|
// CHECK:STDOUT: "start": {
|
|
// CHECK:STDOUT: "character": 0,
|
|
// CHECK:STDOUT: "line": 0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: }Content-Length: 145{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "method": "textDocument/publishDiagnostics",
|
|
// CHECK:STDOUT: "params": {
|
|
// CHECK:STDOUT: "diagnostics": [],
|
|
// CHECK:STDOUT: "uri": "file:///empty.carbon"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }Content-Length: 49{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 4,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": []
|
|
// CHECK:STDOUT: }Content-Length: 51{{\r}}
|
|
// CHECK:STDOUT: {{\r}}
|
|
// CHECK:STDOUT: {
|
|
// CHECK:STDOUT: "id": 5,
|
|
// CHECK:STDOUT: "jsonrpc": "2.0",
|
|
// CHECK:STDOUT: "result": null
|
|
// CHECK:STDOUT: }
|