From d90968dba4dc6a99b9d671a9552ee397793a3a2c Mon Sep 17 00:00:00 2001 From: japhib Date: Sun, 27 Oct 2024 21:29:06 -0600 Subject: [PATCH] Add matching brackets and stub for OnTypeFormatting --- server/src/parser/test/formatter.test.ts | 2 +- server/src/server.ts | 14 +++++++++++++- syntaxes/language-configuration.json | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/server/src/parser/test/formatter.test.ts b/server/src/parser/test/formatter.test.ts index e56441b..8a8062d 100644 --- a/server/src/parser/test/formatter.test.ts +++ b/server/src/parser/test/formatter.test.ts @@ -950,7 +950,7 @@ __lua__ formattedRange: { start: { line: 3, character: 0 }, end: { line: Number.MAX_VALUE, character: 0 }, - } + }, }); }); diff --git a/server/src/server.ts b/server/src/server.ts index d65b89c..dfafe7f 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,6 +1,6 @@ import { CompletionItem, CompletionItemTag, createConnection, DefinitionParams, Diagnostic, DiagnosticSeverity, - DidChangeConfigurationNotification, DocumentFormattingParams, DocumentSymbol, DocumentSymbolParams, + DidChangeConfigurationNotification, DocumentFormattingParams, DocumentOnTypeFormattingParams, DocumentSymbol, DocumentSymbolParams, ExecuteCommandParams, HoverParams, InitializeParams, InitializeResult, Location, Position, ProposedFeatures, Range, ReferenceParams, SignatureHelpParams, SignatureInformation, SymbolKind, TextDocumentPositionParams, TextDocuments, TextDocumentSyncKind, TextEdit, WorkspaceFolder, @@ -56,7 +56,12 @@ connection.onInitialize((params: InitializeParams) => { completionProvider: { triggerCharacters: [ '.', ':' ], resolveProvider: true }, hoverProvider: true, signatureHelpProvider: { triggerCharacters: [ '(' ], retriggerCharacters: [ ',' ] }, + + // Full document formatting documentFormattingProvider: true, + // // Mini-formatting while typing - + // documentOnTypeFormattingProvider: { firstTriggerCharacter: '\n' }, + // Extra formatting commands to vary the style of formatting executeCommandProvider: { commands: [ 'pico8formatFile', @@ -832,6 +837,13 @@ function executeCommand_formatDocument(documentUri: string, opts: FormatterOptio ); } +// Use onDocumentOnTypeFormatting to insert "end" when pressing "enter" after typing the beginning +// of a function, while loop, for loop, etc. +// See: https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/providers/on_type_formatting.ex +connection.onDocumentOnTypeFormatting((params: DocumentOnTypeFormattingParams) => { + +}); + // Make the text document manager listen on the connection // for open, change and close text document events documents.listen(connection); diff --git a/syntaxes/language-configuration.json b/syntaxes/language-configuration.json index 03e9845..edd851d 100644 --- a/syntaxes/language-configuration.json +++ b/syntaxes/language-configuration.json @@ -7,7 +7,12 @@ "brackets": [ ["{", "}"], ["[", "]"], - ["(", ")"] + ["(", ")"], + ["then", "elseif"], + ["then", "end"], + ["do", "end"], + ["function", "end"], + ["repeat", "until"], ], // symbols that are auto closed when typing "autoClosingPairs": [