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

Completion with otter-ls for JS only works for first word in html files #180

Open
dpetka2001 opened this issue Oct 5, 2024 · 0 comments

Comments

@dpetka2001
Copy link

dpetka2001 commented Oct 5, 2024

When I try to write something inside <script> tags in html file, for example document.write("something"), I get completion suggestion for document, but then when i complete it and type . i don't get any more completions for the methods (like write, open, close etc). Minimal repro follows

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

vim.g.mapleader = " "

-- install plugins
local plugins = {
	{ "folke/tokyonight.nvim" },
	{
		"neovim/nvim-lspconfig",
	},
	{
		"williamboman/mason.nvim",
		opts = {},
	},
	{
		"williamboman/mason-lspconfig.nvim",
		opts = {
			ensure_installed = {
				"html",
				"vtsls",
			},
		},
	},
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"hrsh7th/cmp-nvim-lsp",
			"hrsh7th/cmp-buffer",
		},
		opts = function()
			local cmp = require("cmp")
			return {
				snippet = function(args)
					vim.snippet.expand(args.body)
				end,
				mapping = cmp.mapping.preset.insert({
					["<C-b>"] = cmp.mapping.scroll_docs(-4),
					["<C-f>"] = cmp.mapping.scroll_docs(4),
					["<C-Space>"] = cmp.mapping.complete(),
					["<C-e>"] = cmp.mapping.abort(),
					["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
				}),
				sources = cmp.config.sources({
					{ name = "nvim_lsp" },
				}, {
					{ name = "buffer" },
				}),
			}
		end,
	},
	{
		"nvim-treesitter/nvim-treesitter",
		build = ":TSUpdate",
		opts = {
			ensure_installed = {
				"html",
				"javascript",
			},
			highlight = { enable = true },
		},
		config = function(_, opts)
			require("nvim-treesitter.configs").setup(opts)
		end,
	},
	{
		"jmbuhr/otter.nvim",
		opts = {},
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
require("lspconfig").html.setup({})
require("lspconfig").vtsls.setup({})

Run it with nvim -u repro some_file.html and also type :lua require("otter").activate() to start Otter and inside <script> tag try to write document.write("something"). Observe that you get completion for document but not for the method write afterwards. Only completions from buffer nvim-cmp source are available.

PS: For your information on a vanilla JS file I can type document.write and get suggestions for both document at first and afterwards I get suggestions for methods write, close, open etc. so I don't think it's a problem with vtsls LSP server.

PS2: I also did :ls! and the otter buffer for JS is listed, but it always shows line 0 at the end. I would expect that as I move my cursor inside the <script> tag the line 0 in :ls! should also change relative to the position in the JS otter buffer??

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

1 participant