bbatsov / projectile

Project Interaction Library for Emacs
https://docs.projectile.mx
GNU General Public License v3.0
3.95k stars 581 forks source link

Open File creates a new file #1324

Closed BiagioFesta closed 5 years ago

BiagioFesta commented 5 years ago

Expected behavior

We have source files into src/ directory (e.g. src/main.cpp).

Launch the command projectile-find-file and type main. The file main.cpp should be open.

Actual behavior

A new file (empty buffer) will be created instead. The pwd is the "project" directory (.).

Steps to reproduce the problem

Project Tree

.
├── .projectile
├── .gitignore  
├── CMakeLists.txt
├── include
│   └── Foo.hpp
└── src
    ├── Foo.cpp
    └── main.cpp

.projectile content

+/src

Emacs Configuration

;; == Package Managment ==
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

;; == Install UsePackage ==
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

;; == Projectile ==
(use-package projectile
  :ensure t
  :config
  (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
  (projectile-mode +1))

Environment & Version information

Projectile version information

Projectile version: 20181009.851

Emacs version

GNU Emacs 25.2.2

Operating systems

bbatsov commented 5 years ago

Likely I've broken something with my recent refactorings. I'm a bit busy the next couple of weeks, but you can help me out if you'd like to debug where exactly the problem is. See http://www.projectile.mx/en/latest/troubleshooting/ for details.

BiagioFesta commented 5 years ago

I am not familiar with LISP and your project. However, I've tried some investigation at my best.

The issue may be related in the function projectile--find-file

Precisely, when the function calls the function find-file the filename passed will be the following one:

${project_root}/main.cpp

instead of

${project_root}/src/main.cpp

That happens because the function projectile-project-files returns the files inside src directory without the "relative path" from the ${project_root}, that is:

 - main.cpp
 - Foo.cpp

I would expect the project files should be (this is my assumption regarding projectile project):

 - src/main.cpp
 - src/Foo.cpp

In that case, when the find-file will be called the correct filename will be concat.

For example:

${project_root}/src/main.cpp

I hope those information will be useful. if you give me more hits, maybe I can investigate more.

Thank you.

aiba commented 5 years ago

I have the same issue.

It looks like 7b362f67 changed projectile-dir-files to return files relative to the input dir, not the project root dir. projectile-dir-files is called from projectile-project-files.

I think I see how to fix this. I'll try to submit a PR later today.