1
1
use dprint_core:: configuration:: ConfigKeyMap ;
2
2
use dprint_core:: configuration:: GlobalConfiguration ;
3
- use dprint_core:: configuration:: ResolveConfigurationResult ;
4
3
use dprint_core:: generate_plugin_code;
4
+ use dprint_core:: plugins:: CheckConfigUpdatesMessage ;
5
+ use dprint_core:: plugins:: ConfigChange ;
5
6
use dprint_core:: plugins:: FileMatchingInfo ;
6
7
use dprint_core:: plugins:: FormatResult ;
7
8
use dprint_core:: plugins:: PluginInfo ;
9
+ use dprint_core:: plugins:: PluginResolveConfigurationResult ;
10
+ use dprint_core:: plugins:: SyncFormatRequest ;
11
+ use dprint_core:: plugins:: SyncHostFormatRequest ;
8
12
use dprint_core:: plugins:: SyncPluginHandler ;
9
- use dprint_core:: plugins:: SyncPluginInfo ;
10
- use std:: path:: Path ;
11
13
12
14
use super :: configuration:: resolve_config;
13
15
use super :: configuration:: Configuration ;
@@ -19,44 +21,49 @@ impl SyncPluginHandler<Configuration> for JsonPluginHandler {
19
21
& mut self ,
20
22
config : ConfigKeyMap ,
21
23
global_config : & GlobalConfiguration ,
22
- ) -> ResolveConfigurationResult < Configuration > {
23
- resolve_config ( config, global_config)
24
- }
25
-
26
- fn plugin_info ( & mut self ) -> SyncPluginInfo {
27
- let version = env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ;
28
- SyncPluginInfo {
29
- info : PluginInfo {
30
- name : env ! ( "CARGO_PKG_NAME" ) . to_string ( ) ,
31
- version : version. clone ( ) ,
32
- config_key : "json" . to_string ( ) ,
33
- help_url : "https://dprint.dev/plugins/json" . to_string ( ) ,
34
- config_schema_url : format ! (
35
- "https://plugins.dprint.dev/dprint/dprint-plugin-json/{}/schema.json" ,
36
- version
37
- ) ,
38
- update_url : Some ( "https://plugins.dprint.dev/dprint/dprint-plugin-json/latest.json" . to_string ( ) ) ,
39
- } ,
24
+ ) -> PluginResolveConfigurationResult < Configuration > {
25
+ let config = resolve_config ( config, global_config) ;
26
+ PluginResolveConfigurationResult {
27
+ config : config. config ,
28
+ diagnostics : config. diagnostics ,
40
29
file_matching : FileMatchingInfo {
41
30
file_extensions : vec ! [ "json" . to_string( ) , "jsonc" . to_string( ) ] ,
42
31
file_names : vec ! [ ] ,
43
32
} ,
44
33
}
45
34
}
46
35
36
+ fn check_config_updates ( & self , _message : CheckConfigUpdatesMessage ) -> Result < Vec < ConfigChange > , anyhow:: Error > {
37
+ Ok ( Vec :: new ( ) )
38
+ }
39
+
40
+ fn plugin_info ( & mut self ) -> PluginInfo {
41
+ let version = env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ;
42
+ PluginInfo {
43
+ name : env ! ( "CARGO_PKG_NAME" ) . to_string ( ) ,
44
+ version : version. clone ( ) ,
45
+ config_key : "json" . to_string ( ) ,
46
+ help_url : "https://dprint.dev/plugins/json" . to_string ( ) ,
47
+ config_schema_url : format ! (
48
+ "https://plugins.dprint.dev/dprint/dprint-plugin-json/{}/schema.json" ,
49
+ version
50
+ ) ,
51
+ update_url : Some ( "https://plugins.dprint.dev/dprint/dprint-plugin-json/latest.json" . to_string ( ) ) ,
52
+ }
53
+ }
54
+
47
55
fn license_text ( & mut self ) -> String {
48
56
std:: str:: from_utf8 ( include_bytes ! ( "../LICENSE" ) ) . unwrap ( ) . into ( )
49
57
}
50
58
51
59
fn format (
52
60
& mut self ,
53
- file_path : & Path ,
54
- file_bytes : Vec < u8 > ,
55
- config : & Configuration ,
56
- _format_with_host : impl FnMut ( & Path , Vec < u8 > , & ConfigKeyMap ) -> FormatResult ,
61
+ request : SyncFormatRequest < Configuration > ,
62
+ _format_with_host : impl FnMut ( SyncHostFormatRequest ) -> FormatResult ,
57
63
) -> FormatResult {
58
- let file_text = String :: from_utf8 ( file_bytes) ?;
59
- super :: format_text ( file_path, & file_text, config) . map ( |maybe_text| maybe_text. map ( |t| t. into_bytes ( ) ) )
64
+ let file_text = String :: from_utf8 ( request. file_bytes ) ?;
65
+ super :: format_text ( request. file_path , & file_text, request. config )
66
+ . map ( |maybe_text| maybe_text. map ( |t| t. into_bytes ( ) ) )
60
67
}
61
68
}
62
69
0 commit comments