Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(433)

Delta Between Two Patch Sets: src/cmd/godoc/index.go

Issue 189080: code review 189080: Steps towards tracking scopes for identifiers. (Closed)
Left Patch Set: code review 189080: Steps towards tracking scopes for identifiers. Created 15 years, 2 months ago
Right Patch Set: code review 189080: Steps towards tracking scopes for identifiers. Created 15 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/godoc/godoc.go ('k') | src/cmd/godoc/snippet.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file contains the infrastructure to create an 5 // This file contains the infrastructure to create an
6 // (identifier) index for a set of Go files. 6 // (identifier) index for a set of Go files.
7 // 7 //
8 // Basic indexing algorithm: 8 // Basic indexing algorithm:
9 // - traverse all .go files of the file tree specified by root 9 // - traverse all .go files of the file tree specified by root
10 // - for each word (identifier) encountered, collect all occurences (spots) 10 // - for each word (identifier) encountered, collect all occurences (spots)
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 func (x *Indexer) visitComment(c *ast.CommentGroup) { 446 func (x *Indexer) visitComment(c *ast.CommentGroup) {
447 if c != nil { 447 if c != nil {
448 ast.Walk(x, c) 448 ast.Walk(x, c)
449 } 449 }
450 } 450 }
451 451
452 452
453 func (x *Indexer) visitIdent(kind SpotKind, id *ast.Ident) { 453 func (x *Indexer) visitIdent(kind SpotKind, id *ast.Ident) {
454 if id != nil { 454 if id != nil {
455 » » lists, found := x.words[id.Value()] 455 » » lists, found := x.words[id.Name()]
456 if !found { 456 if !found {
457 lists = new(IndexResult) 457 lists = new(IndexResult)
458 » » » x.words[id.Value()] = lists 458 » » » x.words[id.Name()] = lists
459 } 459 }
460 460
461 if kind == Use || x.decl == nil { 461 if kind == Use || x.decl == nil {
462 // not a declaration or no snippet required 462 // not a declaration or no snippet required
463 info := makeSpotInfo(kind, id.Pos().Line, false) 463 info := makeSpotInfo(kind, id.Pos().Line, false)
464 lists.Others.Push(Spot{x.file, info}) 464 lists.Others.Push(Spot{x.file, info})
465 } else { 465 } else {
466 // a declaration with snippet 466 // a declaration with snippet
467 index := x.addSnippet(NewSnippet(x.decl, id)) 467 index := x.addSnippet(NewSnippet(x.decl, id))
468 info := makeSpotInfo(kind, index, true) 468 info := makeSpotInfo(kind, index, true)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 if excludeMainPackages && pkgName(path) == "main" { 599 if excludeMainPackages && pkgName(path) == "main" {
600 return 600 return
601 } 601 }
602 602
603 file, err := parser.ParseFile(path, nil, parser.ParseComments) 603 file, err := parser.ParseFile(path, nil, parser.ParseComments)
604 if err != nil { 604 if err != nil {
605 return // ignore files with (parse) errors 605 return // ignore files with (parse) errors
606 } 606 }
607 607
608 dir, _ := pathutil.Split(path) 608 dir, _ := pathutil.Split(path)
609 » pak := Pak{dir, file.Name.Value()} 609 » pak := Pak{dir, file.Name.Name()}
610 x.file = &File{path, pak} 610 x.file = &File{path, pak}
611 ast.Walk(x, file) 611 ast.Walk(x, file)
612 } 612 }
613 613
614 614
615 // ---------------------------------------------------------------------------- 615 // ----------------------------------------------------------------------------
616 // Index 616 // Index
617 617
618 type LookupResult struct { 618 type LookupResult struct {
619 Decls HitList // package-level declarations (with snippets) 619 Decls HitList // package-level declarations (with snippets)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 745 }
746 746
747 747
748 func (x *Index) Snippet(i int) *Snippet { 748 func (x *Index) Snippet(i int) *Snippet {
749 // handle illegal snippet indices gracefully 749 // handle illegal snippet indices gracefully
750 if 0 <= i && i < len(x.snippets) { 750 if 0 <= i && i < len(x.snippets) {
751 return x.snippets[i] 751 return x.snippets[i]
752 } 752 }
753 return nil 753 return nil
754 } 754 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b