Skip to content

Instantly share code, notes, and snippets.

@rchl
rchl / typescript-helpers.ts
Created April 24, 2023 22:09
TypeScript Helpers
// Forces typescript to expand the type in the hover output. Useful for debugging.
type Prettify<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
@rchl
rchl / region-annotation-st.py
Created April 22, 2023 21:58
ST - High memory usage region annotation
This file has been truncated, but you can view the full file.
import sublime
import sublime_plugin
ANNOTATION_LINK = '<div class="actions" style="font-family:system"><a href=\'subl:lsp_run_text_command_helper {&quot;command&quot;:&quot;lsp_code_actions&quot;,&quot;view_id&quot;:195,&quot;args&quot;:{&quot;code_actions_by_config&quot;:[[&quot;LSP-rome&quot;,[{&quot;kind&quot;:&quot;quickfix.rome.style.noVar&quot;,&quot;title&quot;:&quot;Use &#x27;const&#x27; instead.&quot;,&quot;edit&quot;:{&quot;changes&quot;:{&quot;file:///usr/local/workspace/temp/nuxt3-app/node_modules/logrocket/dist/build.umd.js&quot;:[{&quot;range&quot;:{&quot;start&quot;:{&quot;character&quot;:10,&quot;line&quot;:11},&quot;end&quot;:{&quot;character&quot;:13,&quot;line&quot;:11}},&quot;newText&quot;:&quot;const&quot;}]}},&quot;diagnostics&quot;:[{&quot;source&quot;:&quot;rome&quot;,&quot;code&quot;:&quot;lint/style/noVar&quot;,&quot;codeDescription&quot;:{&quot;href&quot;:&quot;https://docs.rome.tools/lint/rules/noVar&quot;},&quot;range&quot;:{&quot;start&quot;:{&quot;character&quot;:10,&quot;line
@rchl
rchl / adjust_viewport_on_fold.py
Created March 11, 2023 21:21
A Sublime Text plugin for keeping viewport position stable on (un)folding
from typing import Optional, Tuple
import sublime_plugin
class ViewEventListener(sublime_plugin.ViewEventListener):
def on_text_command(self, command_name: str, args: Optional[dict]) -> Optional[Tuple[str, dict]]:
if 'fold' in command_name:
view = self.view
self._old_layout = view.text_to_layout(view.sel()[0].begin())
@rchl
rchl / LSP.sublime-settings
Created December 13, 2021 22:43
vscode-spell-checker configuration in ST
{
"clients": {
"spellcheck": {
"enabled": false,
"command": [
"node",
"/Users/rafal/workspace/github/vscode-spell-checker/packages/_server/dist/main.js",
"--stdio"
],
"selector": "source.js | source.ts",
```python
(module) mdpopups
```
Markdown popup.
Markdown tooltips and phantoms for SublimeText.
TextMate theme to CSS.
https://manual.macromates.com/en/language\_grammars#naming\_conventions
@rchl
rchl / LSP.sublime-settings.jsonc
Last active June 1, 2021 04:24
Configure sheelcheck and flake8 with diagnostic-languageserver for Sublime LSP
{
"clients": {
"diagnostic-ls": {
"enabled": true,
"command": [
"diagnostic-languageserver",
"--stdio"
],
"selector": "source.shell, source.python",
"initializationOptions": {

Nuxt notes

Disable generator runtime for webpack-processed files by setting this in nuxt.config.js:

  build: {
    terser: false,
    babel: {
      presets({ isServer }, [preset, options]) {
 options.targets = isServer ? { node: 'current' } : { chrome: 90 }
@rchl
rchl / Default.js
Last active August 29, 2021 01:30
Sublime Merge quote auto-pairing
// Auto-pair quotes
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double - punctuation.definition.string.end", "match_all": true }
]
},
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"${0:$SELECTION}\""}, "context":
import sublime
import sublime_plugin
class CompletionListener(sublime_plugin.ViewEventListener):
def on_query_completions(self, prefix, locations):
completion_list = sublime.CompletionList()
sublime.set_timeout_async(lambda: self._on_query_completions_async(completion_list, locations[0]))
return completion_list
import sublime
import sublime_plugin
FIRST_RESPONSE_DELAY = 200
SECOND_RESPONSE_DELAY = 2000
class CompletionListener(sublime_plugin.ViewEventListener):
def on_query_completions(self, prefix, locations):