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

No autocomplete suggestion #218

Open
ntdkhang opened this issue May 19, 2023 · 15 comments
Open

No autocomplete suggestion #218

ntdkhang opened this issue May 19, 2023 · 15 comments

Comments

@ntdkhang
Copy link

When I start nvim in a .xcodeproject root, xbase starts running, create the buildServer and .compile file and outputs to log as expected, but there was no autocomplete, not even for basic swift commands. When I deleted xbase and run Sourcekit-lsp on its own, the lsp was working fine, showing suggestions for swift commands and functions in that file (but not methods/classes from other files).

Here's my xbase config

    use {
        'xbase-lab/xbase',
        run = 'make install', -- or "make install && make free_space" (not recommended, longer build time)
        config = function ()
            require'xbase'.setup({
                log_level = vim.log.levels.INFO,
                log_buffer = {
                    focus  = false,
                    default_direction = "horizontal",
                },
                sourcekit = {
                },
                simctl = {
                    iOS = {
                        "iPhone 14 Pro",
                    },
                },
                mappings = {
                    --- Whether xbase mapping should be disabled.
                    enable = true,
                    --- Open build picker. showing targets and configuration.
                    build_picker = 0, --- set to 0 to disable
                    --- Open run picker. showing targets, devices and configuration
                    run_picker = 0, --- set to 0 to disable
                    --- Open watch picker. showing run or build, targets, devices and configuration
                    watch_picker = 0, --- set to 0 to disable
                    --- A list of all the previous pickers
                    all_picker = "<leader>ef", --- set to 0 to disable
                },
            })
        end
    }

My lsp config for sourcekit

local lsp_config = require('lspconfig')
lsp_config.sourcekit.setup{
    root_dir = lsp_config.util.root_pattern("Package.swift", ".git", "*.xcodeproj")
}
lsp.setup()

When I run ~/.local/share/xbase/xbase it knows that I'm editing the file

2023-05-19T15:59:08.344477Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [renamed]
2023-05-19T15:59:08.344504Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift" [created]
2023-05-19T15:59:08.344603Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [created]
2023-05-19T15:59:08.344623Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift" [modified]
2023-05-19T15:59:08.344706Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [modified]
2023-05-19T15:59:08.344726Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift~" [removed]

And here's the xbase-build-server.log

 INFO xbase_sourcekit_helper: Initialized
DEBUG xbase_sourcekit_helper: [ContentView.swift] Querying compile_db
 INFO xbase_sourcekit_helper: 
 INFO xbase_sourcekit_helper: Started
 INFO xbase_sourcekit_helper: Initialized
DEBUG xbase_sourcekit_helper: [ContentView.swift] Querying compile_db
 INFO xbase_sourcekit_helper: 
ERROR xbase_sourcekit_helper: Unhandled params: OptionsChangedRequest { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/dk/Documents/Dev/iOS/PersonalProjects/WeatherClone/WeatherClone/ContentView.swift", query: None, fragment: None }, action: Unregister }
DEBUG xbase_sourcekit_helper: [ContentView.swift] Using Cached file args
 INFO xbase_sourcekit_helper: 

Versions:
macOS 12.5.1
Xcode Version 14.1 (14B47b)

@kkharji
Copy link
Owner

kkharji commented May 22, 2023

Hmmm I believe you haven't installed autocompletor? or which one are you using?

For xbase to take over and configure the setup. You need to have a configuration defined in xbase opts:

      sourcekit = {
        on_attach = function() end,
        handlers = function() end,
        capabilities = function() end,
      },

@ntdkhang
Copy link
Author

I'm using lsp-zero.nvim which requires nvim-lspconfig and mason.nvim.
I tried adding that sourcekit opt and it prints this error when opening the swift file:
[lspconfig] unhandled error: vim/shared.lua:0: after the second argument: expected table, got function

@kkharji
Copy link
Owner

kkharji commented May 22, 2023

Oh, my bad, actually try this:

      sourcekit = {     },

@ntdkhang
Copy link
Author

That's what I did initially and it didn't work

@ntdkhang
Copy link
Author

How did you setup the sourcekit-lsp?

@kkharji
Copy link
Owner

kkharji commented May 22, 2023

Well I have custom setup. I use cmp for completion which has it's own complex setup. hmm I guess maybe you are missing https://github.com/hrsh7th/cmp-nvim-lsp

local dcapabilities = vim.lsp.protocol.make_client_capabilities()
local capabilities = vim.tbl_deep_extend("force", dcapabilities, {
  offsetEncoding = { "utf-16" }, -- fix issue with null-ls and c servers
  experimental = {
    hoverActions = true,
    hoverRange = true,
    serverStatusNotification = true,
    snippetTextEdit = true,
    codeActionGroup = true,
    ssr = true,
  },
  textDocument = {
    completion = {
      completionItem = {
        snippetSupport = true,
        preselectSupport = true,
        insertReplaceSupport = true,
        labelDetailsSupport = true,
        deprecatedSupport = false,
        commitCharactersSupport = true,
        tagSupport = { valueSet = { 1 } },
        resolveSupport = {
          properties = { "additionalTextEdits", "documentation", "detail" },
        },
      },
    },
  },
})

@ntdkhang
Copy link
Author

cmp-nvim-lsp already comes with the lsp-zero setup that I have. The lsp works perfectly for other languages, it work for Swift too (without xbase installed). So I'm wondering if I might be doing anything wrong with my sourcekit-lsp setup that interfere with xbase.

@ntdkhang
Copy link
Author

Here's what :LspInfo shows

 Client: sourcekit (id: 1, bufnr: [5])
 	filetypes:       swift
 	autostart:       true
 	root directory:  /Users/dk/Documents/Dev/iOS/PersonalProject....
 	cmd:             /usr/bin/sourcekit-lsp --log-level error

Then, :LspLog shows this:

[ERROR][2023-05-22 15:53:15] .../vim/lsp/rpc.lua:733	"rpc"	"/usr/bin/sourcekit-lsp"	"stderr"	"thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', crates/sourcekit-helper/src/main.rs:47:59\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"

@kkharji
Copy link
Owner

kkharji commented May 23, 2023

Nice that's a clear lead. I will look into it in few hours. Thanks

@rsdenijs
Copy link

For what it is worth I'm seeing the same problem

 "rpc"   "sourcekit-lsp" "stderr"    "thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', "
 "rpc"   "sourcekit-lsp" "stderr"    "crates/sourcekit-helper/src/main.rs"
 "rpc"   "sourcekit-lsp" "stderr"    ":47:59\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"

@kkharji
Copy link
Owner

kkharji commented Sep 18, 2023

@rsdenijs can you give more information on your project?

@rsdenijs
Copy link

rsdenijs commented Sep 19, 2023

Yes, I am a regular neovim user and was playing around with xcode/swiftUI intro tutorials. I was trying to get some level of LSP working in neovim.

@kkharji
Copy link
Owner

kkharji commented Sep 19, 2023

Yes, I am a regular neovim user and was playing around with xcode/swiftUI intro tutorials. I was trying to get some level of LSP working in neovim.

Oh nice. You ain't using any type of xcodeproj generator just directly from xcode created.

@rsdenijs
Copy link

Correct. Just created the project in Xcode and trying to do some basic development on it in neovim.

@bengidev
Copy link

@kkharji Can you give your setup repos for example purpose, mate?

I think my setup was failed and need some reference to make the plugin works.

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

4 participants