コード例 #1
0
ファイル: main.go プロジェクト: edma2/classy
func plumbDir(idx *index.Index, children []string, w io.Writer) error {
	dirs := make(map[string]int)
	for _, c := range children {
		if get := idx.Get(c); get != nil {
			if get.Path != "" && !strings.Contains(get.Path, "/src/test/") {
				dirs[filepath.Dir(get.Path)]++
			}
		}
	}
	// guess dir to plumb by most common dir
	max := 0
	dir := ""
	for d, n := range dirs {
		if n > max {
			max = n
			dir = d
		}
	}
	log.Println(dirs)
	log.Println(dir)
	if dir == "" {
		return nil
	}
	return plumbDir1(dir, w)
}
コード例 #2
0
ファイル: main.go プロジェクト: edma2/classy
func serve(idx *index.Index) error {
	fid, err := plumb.Open("editclass", plan9.OREAD)
	if err != nil {
		return err
	}
	defer fid.Close()
	r := bufio.NewReader(fid)
	w, err := plumb.Open("send", plan9.OWRITE)
	if err != nil {
		return err
	}
	defer w.Close()
	for {
		m := plumb.Message{}
		err := m.Recv(r)
		if err != nil {
			return err
		}
		log.Printf("Received from plumber: %s\n", m)
		name := string(m.Data)
		var get *index.GetResult
		for _, c := range candidatesOf(name) {
			if get = idx.Get(c); get != nil {
				break
			}
		}
		if get == nil {
			log.Printf("Found no results for: %s\n", name)
			continue
		}
		if get.Path != "" {
			if err := plumbFile(&m, w, name, get.Path); err != nil {
				log.Printf("%s: %s\n", get.Path, err)
			}
		} else if get.Children != nil {
			if err := plumbDir(idx, get.Children, w); err != nil {
				log.Printf("error opening dir: %s\n", err)
			}
		} else {
			log.Printf("Result was empty: %s\n", name)
		}
	}
	return nil
}