Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add matching brackets and stub for OnTypeFormatting #66

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/parser/test/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ __lua__
formattedRange: {
start: { line: 3, character: 0 },
end: { line: Number.MAX_VALUE, character: 0 },
}
},
});
});

Expand Down
14 changes: 13 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion syntaxes/language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
["(", ")"],
["then", "elseif"],
["then", "end"],
["do", "end"],
["function", "end"],
["repeat", "until"],
],
// symbols that are auto closed when typing
"autoClosingPairs": [
Expand Down
Loading