示例#1
0
func (c *Clang) CompleteAt(a *content.CompleteAtArgs, ret *content.CompletionResult) error {
	origargs, _ := a.Settings().Get("compiler_flags").([]string)
	args := make([]string, len(origargs))
	for i := range origargs {
		args[i] = expand_path.ExpandPath(origargs[i])
	}
	fn := a.Location.File.Name

	if cnt := a.Location.File.Contents; cnt != "" {
		if f, err := ioutil.TempFile("", "completion_clang"); err != nil {
			return err
		} else {
			fn = f.Name()
			defer os.Remove(fn)
			fn += filepath.Ext(a.Location.File.Name)
			defer os.Remove(fn)
			if err := ioutil.WriteFile(fn, []byte(cnt), 0644); err != nil {
				return err
			}
		}
		args = append(args, "-I"+filepath.Dir(a.Location.File.Name))
	}

	args = append([]string{"-fsyntax-only", "-Xclang", fmt.Sprintf("-code-completion-at=%s:%d:%d", fn, a.Location.Line, a.Location.Column)}, args...)
	args = append(args, fn)
	if out, err := RunClang(args...); len(out) == 0 {
		return err
	} else if r, err := parseresult(string(out)); err != nil {
		return err
	} else {
		*ret = r
		return nil
	}
}
示例#2
0
func (c *Clang) prepare(a *content.CompleteAtArgs) (fn string, args []string, err error) {
	origargs, _ := a.Settings().Get("compiler_flags").([]string)
	args = make([]string, len(origargs))
	for i := range origargs {
		args[i] = expand_path.ExpandPath(origargs[i])
	}
	fn = a.Location.File.Name
	if a.Location.File.Contents != "" {
		// File is unsaved, so use stdin as the filename
		fn = "-"
	}

	return fn, args, nil
}
func (t *TranslationUnitCache) GetTranslationUnit(filename string, options []string, options_script string, unsaved_files map[string]string) *LockedTranslationUnit {
	t.Lock()
	if tu, ok := t.lut[filename]; !ok {
		t.Unlock()

		// TODO(q): SublimeClang executed opts_script here
		args := make([]string, len(options))
		for i := range options {
			args[i] = expand_path.ExpandPath(options[i])
		}

		log4go.Debug("Will compile file %s with the following options:\n%v", filename, options)
		if tu2 := t.index.Parse(filename, options, unsaved_files, index_parse_options); true || tu2.IsValid() {
			tu = &LockedTranslationUnit{}
			tu.TranslationUnit = tu2
			tu.opts = options
			tu.opts_script = options_script
			t.Lock()
			defer t.Unlock()
			t.lut[filename] = tu
		} else {
			log4go.Warn("Failed to compile %s, %v", filename, tu2)
		}
		return tu
	} else {
		recompile := !reflect.DeepEqual(tu.opts, options) || tu.opts_script != options_script
		if recompile {
			// TODO: need to dispose the tu.. Who's responsible for its disposal?
			delete(t.lut, filename)
		}
		t.Unlock()
		if recompile {
			log4go.Debug("Options change detected. Will recompile %s", filename)
			t.addEx(workunit{filename, options, options_script, nil})
		}
		return tu
	}
	return nil
}