Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noob question: How to create new project? #108

Open
ckilb opened this issue Aug 19, 2022 · 9 comments
Open

Noob question: How to create new project? #108

ckilb opened this issue Aug 19, 2022 · 9 comments

Comments

@ckilb
Copy link

ckilb commented Aug 19, 2022

I successfully installed Telescope & this extension. If i launch neovim i can see this:
Screenshot 2022-08-19 at 15 38 05

How am I able to create a project now?
If I simply press c (or ESC first for normal mode and then c) which is listed as the keyboard shortcut for creating a project nothing really happens.

It would be nice to have some documentation how it works for Neovim beginners like me.

@joaosds
Copy link

joaosds commented Aug 28, 2022

I had the same question and this is what I've found. Hope it helps you:

Apparently, it all comes down to how the extension finds the root directory of the current project. There are two ways:

  1. (LSP) Via the native neovim LSP;
  2. (Pattern) By finding some pattern (e.g.: a .git folder in the project directory).

You can also have both, such that the if one is not detected, the other is used as a fallback. Unfortunately, I only found some explicit configuration files in the alternate version: https://github.com/ahmedkhalf/project.nvim.

I don't know how you are configuring your nvim, but here's how mine is configured - I have a project.nvim file on the 'user' folder and I just call it on the init.lua by using (require("user.project)):

local status_ok, project = pcall(require, "project_nvim")
if not status_ok then
	return
end
project.setup({
  manual_mode = false,

  -- Methods of detecting the root directory. **"lsp"** uses the native neovim
  -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
  -- order matters: if one is not detected, the other is used as fallback. You
  -- can also delete or rearangne the detection methods.
  detection_methods = { "lsp", "pattern" },

  -- All the patterns used to detect root dir, when **"pattern"** is in
  -- detection_methods
  patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },

  -- Table of lsp clients to ignore by name
  -- eg: { "efm", ... }
  ignore_lsp = {},

  -- Don't calculate root dir on specific directories
  -- Ex: { "~/.cargo/*", ... }
  exclude_dirs = {},

  -- Show hidden files in telescope
  show_hidden = false,

  -- When set to false, you will get a message when project.nvim changes your
  -- directory.
  silent_chdir = true,

  -- Path where project.nvim will store the project history for use in
  -- telescope
  datapath = vim.fn.stdpath("data"),
})

local tele_status_ok, telescope = pcall(require, "telescope")
if not tele_status_ok then
	return
end

telescope.load_extension('projects')

You can try pattern and LSP to see which one you like more, or just leave both and delete projects that you eventually don't use repeatedly.

All the best,
João Sobral.

@AntoscencoVladimir
Copy link
Contributor

AntoscencoVladimir commented Sep 4, 2022

Hello @ckilb to add default projects your config of telescope should be like this

telescope.setup {
  defaults = {
    path_display = { "smart" },
  },
  extensions = {
    project = {
      base_dirs = {
        '~/path/to/your/project/',
        '~/path/to/your/project2/',
      }
    },
  },
}

telescope.load_extension('project')

Also you can add new projects by Ctrl + a (within your project root dir) in popup and choose it by Ctrl + l

@finalclass
Copy link

i have a project with git initialized however when I open telescope project and then tap Ctrl + a, nothing happens.

@AntoscencoVladimir
Copy link
Contributor

@finalclass did you bind another action to these keys? Try open telescope usually with Ctrl p then Ctrl a, quit vim then reopen project in vim, then Ctrl p, normally you should see your project there Also after tap Ctrl a, check logs with :messages

@finalclass
Copy link

finalclass commented Sep 19, 2022

I think the problem might be related to something else.
I noticed that when I do telescope function builtin.git_files I get this error:

image

I get this error in every git project I have except one. I have no idea what I did that it's broken but I'm pretty sure this is what broke the telescope.project

@AntoscencoVladimir
Copy link
Contributor

AntoscencoVladimir commented Sep 19, 2022

@finalclass can you send your telescope config? I will try to reproduce, and you are right it looks like it's something with telescope at least according to the logs you sent. There written /home/sel is not a git directory I wonder if you put that path somewhere

@finalclass
Copy link

I load telescope with Packer:

vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
  use("nvim-telescope/telescope.nvim")
  use("nvim-telescope/telescope-project.nvim")
  -- ... other modules ...
end)

local nnoremap = require("finalclass/keymap").nnoremap
require("telescope").load_extension("project")

nnoremap("<leader>ff", "<cmd>Telescope find_files<cr>")
nnoremap("<leader>fs", "<cmd>Telescope git_files<cr>")
nnoremap("<leader>fg", "<cmd>Telescope live_grep<cr>")
nnoremap("<leader>fb", "<cmd>Telescope buffers<cr>")
nnoremap("<leader>dh", "<cmd>Telescope help_tags<cr>")
nnoremap("<leader>fp", function()
	require("telescope").extensions.project.project{}
end)

Where keymap.lua is:

local M = {}

local function bind(op, outer_opts)
    outer_opts = outer_opts or {noremap = true}
    return function(lhs, rhs, opts)
        opts = vim.tbl_extend("force",
            outer_opts,
            opts or {}
        )
        vim.keymap.set(op, lhs, rhs, opts)
    end
end

M.nmap = bind("n", {noremap = true})
-- M.imap = bind("i", {noremap = true})
M.nnoremap = bind("n")
M.vnoremap = bind("v")
M.xnoremap = bind("x")
M.inoremap = bind("i")

return M

Should I have autochdir on?

@finalclass
Copy link

finalclass commented Sep 19, 2022

The problem most probably is because of my wrong assumption, that is: I assume that project is added based on a file I'm currently editing and not based on my working dir. When I open vim in a specific project (in a specific directory of the project) then it works fine. When I move out from this directory to some file from a different project then it stops working.

I'm sorry I come from an emacs background (it's my second week in vim) and I think I treat vim too much like emacs:)

@ElCapitanSponge
Copy link

Hello @ckilb to add default projects your config of telescope should be like this

telescope.setup {
  defaults = {
    path_display = { "smart" },
  },
  extensions = {
    project = {
      base_dirs = {
        '~/path/to/your/project/',
        '~/path/to/your/project2/',
      }
    },
  },
}

telescope.load_extension('project')

Also you can add new projects by Ctrl + a (within your project root dir) in popup and choose it by Ctrl + l

Just came across this issue thread, and your response helped me solve the issue I was currently having. Cheers 🍻 @AntoscencoVladimir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants