@@ -14,8 +14,8 @@ use tower_lsp_server::{
14
14
DidChangeConfigurationParams , DidChangeTextDocumentParams , DidChangeWatchedFilesParams ,
15
15
DidChangeWatchedFilesRegistrationOptions , DidChangeWorkspaceFoldersParams ,
16
16
DidCloseTextDocumentParams , DidOpenTextDocumentParams , DidSaveTextDocumentParams ,
17
- ExecuteCommandParams , InitializeParams , InitializeResult , InitializedParams , Registration ,
18
- ServerInfo , Unregistration , Uri , WorkspaceEdit ,
17
+ DocumentFormattingParams , ExecuteCommandParams , InitializeParams , InitializeResult ,
18
+ InitializedParams , Registration , ServerInfo , TextEdit , Unregistration , Uri , WorkspaceEdit ,
19
19
} ,
20
20
} ;
21
21
@@ -40,6 +40,10 @@ type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;
40
40
41
41
const OXC_CONFIG_FILE : & str = ".oxlintrc.json" ;
42
42
43
+ // max range for LSP integer is 2^31 - 1
44
+ // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseTypes
45
+ const LSP_MAX_INT : u32 = 2u32 . pow ( 31 ) - 1 ;
46
+
43
47
struct Backend {
44
48
client : Client ,
45
49
// Each Workspace has it own worker with Linter (and in the future the formatter).
@@ -159,6 +163,8 @@ impl LanguageServer for Backend {
159
163
if worker. needs_init_linter ( ) . await {
160
164
needed_configurations. insert ( worker. get_root_uri ( ) . clone ( ) , worker) ;
161
165
}
166
+ // ToDo: check for configuration
167
+ worker. init_formatter ( ) . await ;
162
168
}
163
169
164
170
if !needed_configurations. is_empty ( ) {
@@ -562,6 +568,15 @@ impl LanguageServer for Backend {
562
568
563
569
Err ( Error :: invalid_request ( ) )
564
570
}
571
+
572
+ async fn formatting ( & self , params : DocumentFormattingParams ) -> Result < Option < Vec < TextEdit > > > {
573
+ let uri = & params. text_document . uri ;
574
+ let workers = self . workspace_workers . read ( ) . await ;
575
+ let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
576
+ return Ok ( None ) ;
577
+ } ;
578
+ Ok ( worker. format_file ( uri) . await )
579
+ }
565
580
}
566
581
567
582
impl Backend {
0 commit comments