File tree Expand file tree Collapse file tree 4 files changed +22
-16
lines changed
Expand file tree Collapse file tree 4 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pub(crate) enum ViewFileKind {
2323}
2424
2525pub ( crate ) fn view_file ( params : ViewFileParams , state : & WorldState ) -> anyhow:: Result < String > {
26- let doc = state. get_document ( & params. text_document . uri ) ?;
26+ let doc = state. get_document_or_error ( & params. text_document . uri ) ?;
2727
2828 match params. kind {
2929 ViewFileKind :: TreeSitter => {
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pub(crate) fn document_formatting(
2323 state : & WorldState ,
2424) -> anyhow:: Result < Option < Vec < lsp_types:: TextEdit > > > {
2525 let uri = & params. text_document . uri ;
26- let doc = state. get_document ( uri) ?;
26+ let doc = state. get_document_or_error ( uri) ?;
2727
2828 let workspace_settings = lsp_state. workspace_document_settings ( uri) ;
2929
@@ -68,7 +68,7 @@ pub(crate) fn document_range_formatting(
6868 state : & WorldState ,
6969) -> anyhow:: Result < Option < Vec < lsp_types:: TextEdit > > > {
7070 let uri = & params. text_document . uri ;
71- let doc = state. get_document ( uri) ?;
71+ let doc = state. get_document_or_error ( uri) ?;
7272
7373 let workspace_settings = lsp_state. workspace_document_settings ( uri) ;
7474
Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ pub(crate) fn did_change(
167167 state : & mut WorldState ,
168168) -> anyhow:: Result < ( ) > {
169169 let uri = & params. text_document . uri ;
170- let doc = state. get_document_mut ( uri) ?;
170+ let doc = state. get_document_mut_or_error ( uri) ?;
171171 doc. on_did_change ( params) ;
172172
173173 Ok ( ( ) )
@@ -249,7 +249,7 @@ pub(crate) fn did_change_formatting_options(
249249 opts : & FormattingOptions ,
250250 state : & mut WorldState ,
251251) {
252- let Ok ( doc) = state. get_document_mut ( uri) else {
252+ let Some ( doc) = state. get_document_mut ( uri) else {
253253 return ;
254254 } ;
255255
@@ -400,7 +400,7 @@ fn update_documents_config(
400400 let config: DocumentSettings = config. into ( ) ;
401401
402402 // Finally, update the document's config
403- state. get_document_mut ( & uri) ?. settings = config;
403+ state. get_document_mut_or_error ( & uri) ?. settings = config;
404404 }
405405
406406 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -41,19 +41,25 @@ pub(crate) struct WorldState {
4141}
4242
4343impl WorldState {
44- pub ( crate ) fn get_document ( & self , uri : & Url ) -> anyhow:: Result < & Document > {
45- if let Some ( doc) = self . documents . get ( uri) {
46- Ok ( doc)
47- } else {
48- Err ( anyhow ! ( "Can't find document for URI {uri}" ) )
44+ pub ( crate ) fn get_document ( & self , uri : & Url ) -> Option < & Document > {
45+ self . documents . get ( uri)
46+ }
47+
48+ pub ( crate ) fn get_document_mut ( & mut self , uri : & Url ) -> Option < & mut Document > {
49+ self . documents . get_mut ( uri)
50+ }
51+
52+ pub ( crate ) fn get_document_or_error ( & self , uri : & Url ) -> anyhow:: Result < & Document > {
53+ match self . get_document ( uri) {
54+ Some ( doc) => Ok ( doc) ,
55+ None => Err ( anyhow ! ( "Can't find document for URI {uri}" ) ) ,
4956 }
5057 }
5158
52- pub ( crate ) fn get_document_mut ( & mut self , uri : & Url ) -> anyhow:: Result < & mut Document > {
53- if let Some ( doc) = self . documents . get_mut ( uri) {
54- Ok ( doc)
55- } else {
56- Err ( anyhow ! ( "Can't find document for URI {uri}" ) )
59+ pub ( crate ) fn get_document_mut_or_error ( & mut self , uri : & Url ) -> anyhow:: Result < & mut Document > {
60+ match self . get_document_mut ( uri) {
61+ Some ( doc) => Ok ( doc) ,
62+ None => Err ( anyhow ! ( "Can't find document for URI {uri}" ) ) ,
5763 }
5864 }
5965
You can’t perform that action at this time.
0 commit comments