解決 PhpStorm 遇到 Selected element is used for non-project files 錯誤訊息

PhpStorm 修改檔案時,出現錯誤訊息「Selected element is used for non-project files. These usages won't be renamed. 」解決方式 (1) 先確認檔案是否放在專案目錄夾內,如果不是,則考慮是否要將檔案移到專案資料夾內 (2) 如果檔案已經在專案目錄夾內,刪除專案目錄內 .idea 隱藏目錄,重設專案設定即可恢復正常。 

Copyright © 2021 JetBrains s.r.o. PhpStorm and the PhpStorm logo are registered trademarks of JetBrains s.r.o.


問題描述

明明檔案已經放在專案目錄內,檔案更名仍然會出現錯誤訊息「Cannot perform refactoring. Selected element is used for non-project files. These usages won't be renamed. Process anyway?」或幾乎修改每個檔案都會遇到「This file does not belong to the project ... I want to edit this file anyway」
Cannot perform refactoring. Selected element is used for non-project files. These usages won't be renamed. Process anyway?

解決方式

PhpStorm 的專案是以資料夾組織,例如資料夾 project_folder 內的檔案或子資料夾,都屬於同一專案。先確認檔案是否放在專案資料夾內:

1. 如果要修改檔案沒有放在專案資料夾內,則考慮是否要將檔案移到專案資料夾內 
2. 如果檔案已經在專案目錄夾內,需要刪除專案目錄內 .idea 隱藏目錄,重設專案設定即可恢復正常。 

    (1) PhpStorm 關閉該專案 

    (2) 打開檔案管理 Finder

    (3) 切換到專案資料夾,可以看到專案的其他檔案與資料夾


    (4) 如果無法看到隱藏資料夾 .idea,需要先設定可以在 Mac 顯示隱藏檔案和資料夾,可參考 如何在Mac上顯示隱藏檔案和檔案夾? – 資安趨勢部落格

    (5) 刪除隱藏資料夾 .idea 

    (6) 回到 PhpStorm 重新打開專案資料夾,即可解決 

JetBrains 文件說明 .idea 資料夾存放專案設定,可能是建立新專案時,將其他專案設定複製過來導致發生錯誤。刪除 .idea 資料夾, PhpStorm 再重新打開專案,會自動產生新的 .idea 資料夾。

參考資料

  1. Non-Project Files Protection dialog | IntelliJ IDEA
  2. What is the .idea folder? – Rider Support | JetBrains
  3. node.js - WebStorm has marked all files in a directory as non-project files - Stack Overflow
  4. 如何在Mac上顯示隱藏檔案和檔案夾? – 資安趨勢部落格



留言