Skip to content

Commit 133e5e4

Browse files
committed
refactor!: editor sections
Editor can now be split into multiple sections wrapped in `@leet` tags. Imports are now by default wrapped in `@leet imports` tags and folded when opening a problem. To disable this behavior, disable `editor.fold_imports`.
1 parent 7bbeeaf commit 133e5e4

File tree

8 files changed

+261
-123
lines changed

8 files changed

+261
-123
lines changed

‎README.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,26 @@ logging = true
254254

255255
Inject code before or after your solution, injected code won't be submitted or run.
256256

257-
#### default imports
258-
259-
You can also pass `before = true` to inject default imports for the language.
260-
Supported languages are `python`, `python3`, `java`
261-
262-
Access default imports via `require("leetcode.config.imports")`
257+
Imports will be injected at the top of the buffer, automatically
258+
folded by default.
263259

264260
```lua
265261
injector = { ---@type table<lc.lang, lc.inject>
266262
["python3"] = {
267-
before = true
263+
imports = function(default_imports)
264+
vim.list_extend(default_imports, { "from .leetcode import *" })
265+
return default_imports
266+
end,
267+
after = { "def test():", " print('test')" },
268268
},
269269
["cpp"] = {
270-
before = { "#include <bits/stdc++.h>", "using namespace std;" },
270+
imports = function()
271+
-- return a different list to omit default imports
272+
return { "#include <bits/stdc++.h>", "using namespace std;" }
273+
end,
271274
after = "int main() {}",
272275
},
273-
["java"] = {
274-
before = "import java.util.*;",
275-
},
276-
}
276+
},
277277
```
278278

279279
### picker
@@ -354,7 +354,7 @@ image_support = false,
354354

355355
- `tabs` opens a picker with all currently opened question tabs
356356

357-
- `yank` yanks the current question solution
357+
- `yank` yanks the code section
358358

359359
- `lang` opens a picker to change the language of the current question
360360

@@ -366,25 +366,27 @@ image_support = false,
366366

367367
- `random` opens a random question
368368

369-
- `daily` opens the question of today
369+
- `daily` opens the question of today problem
370370

371-
- `list` opens a problem list picker
371+
- `list` opens a picker with all available leetcode problems
372372

373373
- `open` opens the current question in a default browser
374374

375-
- `reset` reset current question to default code definition
375+
- `restore` try to restore default question layout
376376

377-
- `last_submit` retrieve last submitted code for the current question
377+
- `last_submit` tries to replace the editor code section with the latest submitted code
378378

379-
- `restore` try to restore default question layout
379+
- `reset` resets editor code section to the default snippet
380380

381-
- `inject` re-inject code for the current question
381+
- `inject` re-injects editor code, keeping the code section intact
382382

383-
- `session`
384-
- `create` create a new session
385-
- `change` change the current session
383+
- `fold` applies folding to the current question imports section
386384

387-
- `update` update the current session in case it went out of sync
385+
<!-- - `session` -->
386+
<!-- - `create` create a new session -->
387+
<!-- - `change` change the current session -->
388+
<!---->
389+
<!-- - `update` update the current session in case it went out of sync -->
388390

389391
- `desc` toggle question description
390392
- `toggle` same as `Leet desc`
@@ -394,10 +396,10 @@ image_support = false,
394396
- `cookie`
395397
- `update` opens a prompt to enter a new cookie
396398

397-
- `delete` sign-out
399+
- `delete` deletes stored cookie and logs out of [leetcode.nvim]
398400

399401
- `cache`
400-
- `update` updates cache
402+
- `update` fetches all available problems and updates the local cache of [leetcode.nvim]
401403

402404
#### Some commands can take optional arguments. To stack argument values separate them by a `,`
403405

@@ -424,9 +426,10 @@ This plugin can be initiated in two ways:
424426
nvim leetcode.nvim
425427
```
426428

427-
- _**(Experimental)**_ Alternatively, you can use `:Leet` command to open [leetcode.nvim]
429+
- Use `:Leet` command to open [leetcode.nvim]
428430
within your preferred dashboard plugin. The only requirement is that [Neovim]
429431
must not have any listed buffers open.
432+
To bypass this requirement use [`non_standalone`](#non-standalone-mode) plugin.
430433

431434
### Switching between questions
432435

‎lua/leetcode-ui/layout/console.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function ConsoleLayout:mount()
6060
end
6161

6262
function ConsoleLayout:run(submit)
63+
if not self.question:editor_section_is_present("code") then
64+
return
65+
end
66+
6367
if config.user.console.open_on_runcode then
6468
self:show()
6569
end

0 commit comments

Comments
 (0)