aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-11 11:31:50 +0100
committerAleksey Kladov <[email protected]>2020-07-11 11:31:50 +0100
commit3fc4916b53894c63320e31855e3c62b974dfcc95 (patch)
tree727e44223da0b60fa01f41ad6b2d26cc9b5cc2c5 /crates
parent6c1546c3a495785cf293dbbfb7f65ea124602528 (diff)
Reduce visibility
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/semantics.rs62
1 files changed, 31 insertions, 31 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 4a16ac566..97125b32a 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -270,17 +270,17 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
270} 270}
271 271
272impl<'db> SemanticsImpl<'db> { 272impl<'db> SemanticsImpl<'db> {
273 pub fn new(db: &'db dyn HirDatabase) -> Self { 273 fn new(db: &'db dyn HirDatabase) -> Self {
274 Self { db, s2d_cache: Default::default(), cache: Default::default() } 274 Self { db, s2d_cache: Default::default(), cache: Default::default() }
275 } 275 }
276 276
277 pub fn parse(&self, file_id: FileId) -> ast::SourceFile { 277 fn parse(&self, file_id: FileId) -> ast::SourceFile {
278 let tree = self.db.parse(file_id).tree(); 278 let tree = self.db.parse(file_id).tree();
279 self.cache(tree.syntax().clone(), file_id.into()); 279 self.cache(tree.syntax().clone(), file_id.into());
280 tree 280 tree
281 } 281 }
282 282
283 pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> { 283 fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
284 let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call); 284 let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call);
285 let sa = self.analyze2(macro_call.map(|it| it.syntax()), None); 285 let sa = self.analyze2(macro_call.map(|it| it.syntax()), None);
286 let file_id = sa.expand(self.db, macro_call)?; 286 let file_id = sa.expand(self.db, macro_call)?;
@@ -289,7 +289,7 @@ impl<'db> SemanticsImpl<'db> {
289 Some(node) 289 Some(node)
290 } 290 }
291 291
292 pub fn expand_hypothetical( 292 fn expand_hypothetical(
293 &self, 293 &self,
294 actual_macro_call: &ast::MacroCall, 294 actual_macro_call: &ast::MacroCall,
295 hypothetical_args: &ast::TokenTree, 295 hypothetical_args: &ast::TokenTree,
@@ -310,7 +310,7 @@ impl<'db> SemanticsImpl<'db> {
310 ) 310 )
311 } 311 }
312 312
313 pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken { 313 fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
314 let parent = token.parent(); 314 let parent = token.parent();
315 let parent = self.find_file(parent); 315 let parent = self.find_file(parent);
316 let sa = self.analyze2(parent.as_ref(), None); 316 let sa = self.analyze2(parent.as_ref(), None);
@@ -334,7 +334,7 @@ impl<'db> SemanticsImpl<'db> {
334 token.value 334 token.value
335 } 335 }
336 336
337 pub fn descend_node_at_offset( 337 fn descend_node_at_offset(
338 &self, 338 &self,
339 node: &SyntaxNode, 339 node: &SyntaxNode,
340 offset: TextSize, 340 offset: TextSize,
@@ -346,24 +346,24 @@ impl<'db> SemanticsImpl<'db> {
346 .flatten() 346 .flatten()
347 } 347 }
348 348
349 pub fn original_range(&self, node: &SyntaxNode) -> FileRange { 349 fn original_range(&self, node: &SyntaxNode) -> FileRange {
350 let node = self.find_file(node.clone()); 350 let node = self.find_file(node.clone());
351 original_range(self.db, node.as_ref()) 351 original_range(self.db, node.as_ref())
352 } 352 }
353 353
354 pub fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { 354 fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
355 let src = diagnostics.source(); 355 let src = diagnostics.source();
356 let root = self.db.parse_or_expand(src.file_id).unwrap(); 356 let root = self.db.parse_or_expand(src.file_id).unwrap();
357 let node = src.value.to_node(&root); 357 let node = src.value.to_node(&root);
358 original_range(self.db, src.with_value(&node)) 358 original_range(self.db, src.with_value(&node))
359 } 359 }
360 360
361 pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ { 361 fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
362 let node = self.find_file(node); 362 let node = self.find_file(node);
363 node.ancestors_with_macros(self.db.upcast()).map(|it| it.value) 363 node.ancestors_with_macros(self.db.upcast()).map(|it| it.value)
364 } 364 }
365 365
366 pub fn ancestors_at_offset_with_macros( 366 fn ancestors_at_offset_with_macros(
367 &self, 367 &self,
368 node: &SyntaxNode, 368 node: &SyntaxNode,
369 offset: TextSize, 369 offset: TextSize,
@@ -373,64 +373,64 @@ impl<'db> SemanticsImpl<'db> {
373 .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len()) 373 .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
374 } 374 }
375 375
376 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { 376 fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
377 self.analyze(expr.syntax()).type_of_expr(self.db, &expr) 377 self.analyze(expr.syntax()).type_of_expr(self.db, &expr)
378 } 378 }
379 379
380 pub fn type_of_pat(&self, pat: &ast::Pat) -> Option<Type> { 380 fn type_of_pat(&self, pat: &ast::Pat) -> Option<Type> {
381 self.analyze(pat.syntax()).type_of_pat(self.db, &pat) 381 self.analyze(pat.syntax()).type_of_pat(self.db, &pat)
382 } 382 }
383 383
384 pub fn type_of_self(&self, param: &ast::SelfParam) -> Option<Type> { 384 fn type_of_self(&self, param: &ast::SelfParam) -> Option<Type> {
385 self.analyze(param.syntax()).type_of_self(self.db, &param) 385 self.analyze(param.syntax()).type_of_self(self.db, &param)
386 } 386 }
387 387
388 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 388 fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
389 self.analyze(call.syntax()).resolve_method_call(self.db, call) 389 self.analyze(call.syntax()).resolve_method_call(self.db, call)
390 } 390 }
391 391
392 pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<Field> { 392 fn resolve_field(&self, field: &ast::FieldExpr) -> Option<Field> {
393 self.analyze(field.syntax()).resolve_field(self.db, field) 393 self.analyze(field.syntax()).resolve_field(self.db, field)
394 } 394 }
395 395
396 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { 396 fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> {
397 self.analyze(field.syntax()).resolve_record_field(self.db, field) 397 self.analyze(field.syntax()).resolve_record_field(self.db, field)
398 } 398 }
399 399
400 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { 400 fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> {
401 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) 401 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
402 } 402 }
403 403
404 pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { 404 fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> {
405 let sa = self.analyze(macro_call.syntax()); 405 let sa = self.analyze(macro_call.syntax());
406 let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call); 406 let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call);
407 sa.resolve_macro_call(self.db, macro_call) 407 sa.resolve_macro_call(self.db, macro_call)
408 } 408 }
409 409
410 pub fn resolve_path(&self, path: &ast::Path) -> Option<PathResolution> { 410 fn resolve_path(&self, path: &ast::Path) -> Option<PathResolution> {
411 self.analyze(path.syntax()).resolve_path(self.db, path) 411 self.analyze(path.syntax()).resolve_path(self.db, path)
412 } 412 }
413 413
414 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 414 fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> {
415 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit) 415 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
416 } 416 }
417 417
418 pub fn lower_path(&self, path: &ast::Path) -> Option<Path> { 418 fn lower_path(&self, path: &ast::Path) -> Option<Path> {
419 let src = self.find_file(path.syntax().clone()); 419 let src = self.find_file(path.syntax().clone());
420 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into())) 420 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into()))
421 } 421 }
422 422
423 pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { 423 fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> {
424 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat) 424 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat)
425 } 425 }
426 426
427 pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { 427 fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> {
428 self.analyze(literal.syntax()) 428 self.analyze(literal.syntax())
429 .record_literal_missing_fields(self.db, literal) 429 .record_literal_missing_fields(self.db, literal)
430 .unwrap_or_default() 430 .unwrap_or_default()
431 } 431 }
432 432
433 pub fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> { 433 fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> {
434 self.analyze(pattern.syntax()) 434 self.analyze(pattern.syntax())
435 .record_pattern_missing_fields(self.db, pattern) 435 .record_pattern_missing_fields(self.db, pattern)
436 .unwrap_or_default() 436 .unwrap_or_default()
@@ -442,23 +442,23 @@ impl<'db> SemanticsImpl<'db> {
442 f(&mut ctx) 442 f(&mut ctx)
443 } 443 }
444 444
445 pub fn to_module_def(&self, file: FileId) -> Option<Module> { 445 fn to_module_def(&self, file: FileId) -> Option<Module> {
446 self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from) 446 self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from)
447 } 447 }
448 448
449 pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> { 449 fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
450 let node = self.find_file(node.clone()); 450 let node = self.find_file(node.clone());
451 let resolver = self.analyze2(node.as_ref(), None).resolver; 451 let resolver = self.analyze2(node.as_ref(), None).resolver;
452 SemanticsScope { db: self.db, resolver } 452 SemanticsScope { db: self.db, resolver }
453 } 453 }
454 454
455 pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> { 455 fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
456 let node = self.find_file(node.clone()); 456 let node = self.find_file(node.clone());
457 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; 457 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
458 SemanticsScope { db: self.db, resolver } 458 SemanticsScope { db: self.db, resolver }
459 } 459 }
460 460
461 pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { 461 fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
462 let resolver = def.id.resolver(self.db.upcast()); 462 let resolver = def.id.resolver(self.db.upcast());
463 SemanticsScope { db: self.db, resolver } 463 SemanticsScope { db: self.db, resolver }
464 } 464 }
@@ -490,14 +490,14 @@ impl<'db> SemanticsImpl<'db> {
490 SourceAnalyzer::new_for_resolver(resolver, src) 490 SourceAnalyzer::new_for_resolver(resolver, src)
491 } 491 }
492 492
493 pub fn cache(&self, root_node: SyntaxNode, file_id: HirFileId) { 493 fn cache(&self, root_node: SyntaxNode, file_id: HirFileId) {
494 assert!(root_node.parent().is_none()); 494 assert!(root_node.parent().is_none());
495 let mut cache = self.cache.borrow_mut(); 495 let mut cache = self.cache.borrow_mut();
496 let prev = cache.insert(root_node, file_id); 496 let prev = cache.insert(root_node, file_id);
497 assert!(prev == None || prev == Some(file_id)) 497 assert!(prev == None || prev == Some(file_id))
498 } 498 }
499 499
500 pub fn assert_contains_node(&self, node: &SyntaxNode) { 500 fn assert_contains_node(&self, node: &SyntaxNode) {
501 self.find_file(node.clone()); 501 self.find_file(node.clone());
502 } 502 }
503 503
@@ -506,7 +506,7 @@ impl<'db> SemanticsImpl<'db> {
506 cache.get(root_node).copied() 506 cache.get(root_node).copied()
507 } 507 }
508 508
509 pub fn find_file(&self, node: SyntaxNode) -> InFile<SyntaxNode> { 509 fn find_file(&self, node: SyntaxNode) -> InFile<SyntaxNode> {
510 let root_node = find_root(&node); 510 let root_node = find_root(&node);
511 let file_id = self.lookup(&root_node).unwrap_or_else(|| { 511 let file_id = self.lookup(&root_node).unwrap_or_else(|| {
512 panic!( 512 panic!(