Skip to content

Commit

Permalink
[SERVER] Auto formatting draft
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Jun 21, 2024
1 parent 5f237ff commit 63e4eef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions hexa.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"main",
"cli/symlink",
"cli/init",
"server/format",
"server"
],
"define":
Expand Down
8 changes: 8 additions & 0 deletions source/server.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ enum ServerCommandKind : String {
FindProjectFile

// Uses `FindProjectFile` internally
// TODO reanme to AutoCheck
AutocheckProject

// IntelliSense
CompletionItemProvider
DocumentSymbolProvider
HoverProvider

// Refactoring
WholeDocumentFormatting

// Deprecated commands here
}

Expand Down Expand Up @@ -677,6 +681,10 @@ class Server {
}
}

case WholeDocumentFormatting: {
response.push({content: autoFormatWholeFile(command.payload)})
}

case SyncFileContents:
let fsPath: String = command.payload.fsPath
let content: String = command.payload.content
Expand Down
1 change: 0 additions & 1 deletion source/server/autoformat.hexa

This file was deleted.

32 changes: 32 additions & 0 deletions source/server/format.hexa
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// The Hexa Compiler
// Copyright (C) 2024 Oleh Petrenko
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

fun autoFormatWholeFile(file: String): String {
let project = new Project()
let content = Buffer.from(file)
try {
let tokens = Lexer.tokenize(content, 'hexa.hexa')
try {
let nodes = Parser.parseNodes(tokens, project, lint: true)
return file
} catch e: CompilerErrors {
return file
}
} catch e: CompilerErrors {
return file
}

return file
}

0 comments on commit 63e4eef

Please sign in to comment.