Skip to content

Commit

Permalink
feat: add filetype module (#1500)
Browse files Browse the repository at this point in the history
* feat: add filetype module

* ci(test): filetype detection for notebook cells
  • Loading branch information
xiyaowong committed Oct 7, 2023
1 parent 4d7a9be commit 56fbadc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/lua/vscode-neovim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local defaults = require("vscode-neovim.defaults")
local cursor = require("vscode-neovim.cursor")

require("vscode-neovim.highlight")
require("vscode-neovim.filetype")

local M = {}

Expand Down
14 changes: 14 additions & 0 deletions runtime/lua/vscode-neovim/filetype.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
vim.filetype.add({
pattern = {
-- To ensure that the user's fallback pattern is not overridden.
[".*.*.*"] = {
priority = -math.huge,
function(_, bufnr)
local name = vim.api.nvim_buf_get_name(bufnr)
if name:match("vscode%-notebook%-cell") then
return "python"
end
end,
},
},
})
14 changes: 14 additions & 0 deletions src/test/suite/vscode-integration-specific.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ describe("VSCode integration specific stuff", () => {
assert.strictEqual("typescript", type);
});

it("Filetype detection (jupyter notebook)", async function () {
this.retries(2);

const note = await vscode.workspace.openNotebookDocument(
vscode.Uri.file(path.join(__dirname, "../../../test_fixtures/window-changed.ipynb")),
);
await vscode.window.showNotebookDocument(note, { viewColumn: vscode.ViewColumn.One });
await wait(1000);

const buf = await client.buffer;
const type = await client.request("nvim_buf_get_option", [buf.id, "filetype"]);
assert.strictEqual("python", type);
});

it("Next search result works", async () => {
await openTextDocument(path.join(__dirname, "../../../test_fixtures/incsearch-scroll.ts"));

Expand Down

0 comments on commit 56fbadc

Please sign in to comment.