{"@attributes":{"version":"2.0"},"channel":{"title":"this, that and more","description":"mostly dev stuff, sometimes life","link":"https:\/\/duswnchl.github.io\/tags\/igalia-planet\/","pubDate":"Tue, 31 Mar 2026 03:00:45 +0000","lastBuildDate":"Tue, 31 Mar 2026 03:00:45 +0000","generator":"Jekyll v4.4.1","item":[{"title":"Smarter Chromium GN in Vim with gn-language-server","description":"<p>GN Language Server for Chromium development was announced on <a href=\"https:\/\/groups.google.com\/a\/chromium.org\/g\/chromium-dev\/c\/uTa5mrlvbvw\/m\/vTVpKZPVDwAJ\">chromium-dev<\/a>.\nIt\u2019s very easy to install in VSCode, NeoVim or Emacs. But how can we configure\nit with classic Vim + <a href=\"https:\/\/github.com\/ycm-core\/YouCompleteMe\">YCM<\/a>?<\/p>\n\n<h2 id=\"setup\">Setup<\/h2>\n\n<p>First, install the language server with Cargo.<\/p>\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>cargo <span class=\"nb\">install<\/span> <span class=\"nt\">--locked<\/span> gn-language-server\n<\/code><\/pre><\/div><\/div>\n<p>Then, add this to your vimrc.<\/p>\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">let <\/span>g:ycm_language_server <span class=\"o\">=<\/span> <span class=\"o\">[<\/span>\n      <span class=\"se\">\\ <\/span><span class=\"o\">{<\/span>\n      <span class=\"se\">\\ <\/span>  <span class=\"s1\">'name'<\/span>: <span class=\"s1\">'gn'<\/span>,\n      <span class=\"se\">\\ <\/span>  <span class=\"s1\">'cmdline'<\/span>: <span class=\"o\">[<\/span> <span class=\"s1\">'gn-language-server'<\/span> <span class=\"o\">]<\/span>,\n      <span class=\"se\">\\ <\/span>  <span class=\"s1\">'filetypes'<\/span>: <span class=\"o\">[<\/span> <span class=\"s1\">'gn'<\/span> <span class=\"o\">]<\/span>,\n      <span class=\"se\">\\ <\/span><span class=\"o\">}<\/span>\n  <span class=\"se\">\\ <\/span><span class=\"o\">]<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>That easy, right?<\/p>\n\n<h2 id=\"whats-working\">What\u2019s Working<\/h2>\n\n<h3 id=\"hover-documentation\">Hover Documentation<\/h3>\n<p><img src=\"\/assets\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/hover.gif\" alt=\"hover\" \/><\/p>\n<h3 id=\"go-to-imports\">Go To Imports<\/h3>\n<p><img src=\"\/assets\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/jump_import.gif\" alt=\"jump_import\" \/><\/p>\n<h3 id=\"go-to-dependencies\">Go To Dependencies<\/h3>\n<p><img src=\"\/assets\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/jump_deps.gif\" alt=\"jump_deps\" \/><\/p>\n\n<h2 id=\"current-limitations\">Current Limitations<\/h2>\n<p>The following features are not working yet. They may need more configuration or\nfurther work:<\/p>\n\n<h3 id=\"code-folding\">Code Folding<\/h3>\n<p>Classic Vim and YCM don\u2019t support LSP-based folding, and I\u2019m not a big fan of\nthat feature anyway. But you can configure another plugin that supports\nLSP-based folding, or simply rely on indent-based folding.<\/p>\n\n<h3 id=\"go-to-definition\">Go To Definition<\/h3>\n<p>When I try to go to the definition of <code class=\"language-plaintext highlighter-rouge\">template<\/code>, I get an error <code class=\"language-plaintext highlighter-rouge\">KeyError:\n'uri'<\/code>. I\u2019m not sure whether this is caused by my local configuration, but it\nneeds further investigation.\n<img src=\"\/assets\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/go_def_error.gif\" alt=\"go_def_error\" \/><\/p>\n\n","pubDate":"Tue, 10 Mar 2026 03:06:00 +0000","link":"https:\/\/duswnchl.github.io\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/","guid":"https:\/\/duswnchl.github.io\/posts\/smarter-chromium-gn-in-vim-with-gn-language-server\/","category":["chromium","igalia-planet","dyk"]},{"title":"Tips for using Vim when developing Chromium","description":"<p>There are lots of powerful IDEs which are broadly used by developers. Vim is a\ntext editor, but it can be turned into a good IDE with awesome plugins and a\nlittle bit of configuration.<\/p>\n\n<p>Many people already prefer using Vim to develop software because of its\nlightness and availability. I am one of them, and always use Vim to develop\nChromium. However, someone would think that it\u2019s hard to get Vim to reach the\nsame performance as other IDEs, since Chromium is a very huge project.<\/p>\n\n<p>For those potential users, this post introduces some tips for using Vim as an\nIDE when developing Chromium.<\/p>\n\n<blockquote class=\"prompt-info\">\n  <p>The context of this document is for Linux users who are used to using Vim.<\/p>\n<\/blockquote>\n\n<h2 id=\"code-formatting\">Code Formatting<\/h2>\n<p>I strongly recommend using <a href=\"https:\/\/github.com\/google\/vim-codefmt\">vim-codefmt<\/a> for code formatting. It supports\nmost file types in Chromium including GN (See <a href=\"https:\/\/source.chromium.org\/gn\/gn\/+\/main:misc\/vim\/README.md\">GN docs<\/a>) and autoformatting.\nHowever, I don\u2019t like to use autoformatting and just bind <code class=\"language-plaintext highlighter-rouge\">:FormatLines<\/code> to\n<code class=\"language-plaintext highlighter-rouge\">ctrl-I<\/code> for formating a selected visual block.<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>map &lt;C-I&gt; :FormatLines&lt;CR&gt;\n<\/code><\/pre><\/div><\/div>\n\n<p><img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/codefmt.gif\" alt=\"codefmt\" \/><\/p>\n\n<p>Another option is using <code class=\"language-plaintext highlighter-rouge\">clang-format<\/code> in <code class=\"language-plaintext highlighter-rouge\">depot_tools<\/code> by <code class=\"language-plaintext highlighter-rouge\">clang-format.vim<\/code> in\n<a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/vim\">tools\/vim<\/a>. Please check about <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/vim\">tools\/vim<\/a> at the following section.<\/p>\n\n<h2 id=\"toolsvim\">tools\/vim<\/h2>\n\n<p>You can easily find a bunch of Vim files in <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/vim\">tools\/vim<\/a>. I create a <em>.vimrc<\/em>\nfile locally in a working directory and load only what I need.<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">let <\/span><span class=\"nv\">chtool_path<\/span><span class=\"o\">=<\/span>getcwd<span class=\"o\">()<\/span>.<span class=\"s1\">'\/tools'<\/span>\n\nfiletype off\n<span class=\"nb\">let<\/span> &amp;rtp.<span class=\"o\">=<\/span><span class=\"s1\">','<\/span>.chtool_path.<span class=\"s1\">'\/vim\/mojom'<\/span>\n<span class=\"nb\">exec<\/span> <span class=\"s1\">'source'<\/span> chtool_path.<span class=\"s1\">'\/vim\/filetypes.vim'<\/span>\n<span class=\"nb\">exec<\/span> <span class=\"s1\">'source'<\/span> chtool_path.<span class=\"s1\">'\/vim\/ninja-build.vim'<\/span>\nfiletype plugin indent on\n<\/code><\/pre><\/div><\/div>\n\n<p>Chromium provides vimscript files for syntax highliting and file detection of\nMojom, which is the IDL for Mojo interfaces (IPC) among Chromium services. And\n<code class=\"language-plaintext highlighter-rouge\">ninja-build.vim<\/code> allows you compile a file with <code class=\"language-plaintext highlighter-rouge\">ctrl-O<\/code> or build the specific\ntarget with <code class=\"language-plaintext highlighter-rouge\">:CrBuild<\/code> command. See each Vim files for details.<\/p>\n\n<h3 id=\"running-tests\">Running Tests<\/h3>\n\n<p><a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/autotest.py\">tools\/autotest.py<\/a> is very useful when you run tests of Chromium. As the\ndescription of the script, <code class=\"language-plaintext highlighter-rouge\">autotest.py<\/code> finds the appropriate test suits and\nbuilds it, then runs it. <code class=\"language-plaintext highlighter-rouge\">!<\/code> is an option for running <code class=\"language-plaintext highlighter-rouge\">autotest.py<\/code> inside Vim,\nbut sometimes it\u2019s a hassle to type all parameters. What about to write simple\ncommands (or functions) with scripts under <code class=\"language-plaintext highlighter-rouge\">tools\/vim<\/code>?<\/p>\n\n<p>This is an example script for running a test for the current line. Some codes\nare copied from <code class=\"language-plaintext highlighter-rouge\">ninja-build.vim<\/code> and imported from <code class=\"language-plaintext highlighter-rouge\">ninja-output.py<\/code>.<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>pythonx <span class=\"o\">&lt;&lt;<\/span> <span class=\"no\">endpython<\/span><span class=\"sh\">\nimport os, vim\n\ndef path_to_build_dir():\n  # Codes from tools\/vim\/ninja-build.vim.\n  chrome_root = os.path.dirname(vim.current.buffer.name)\n  fingerprints = ['chrome', 'net', 'v8', 'build', 'skia']\n  while chrome_root  and not all(\n      [os.path.isdir(os.path.join(chrome_root , fp)) for fp in fingerprints]):\n    chrome_root = os.path.dirname(chrome_root)\n  sys.path.append(os.path.join(chrome_root, 'tools', 'vim'))\n  # Import GetNinjaOutputDirectory from tools\/vim\/ninja_output.py.\n  from ninja_output import GetNinjaOutputDirectory\n  return GetNinjaOutputDirectory(chrome_root)\n\ndef run_test_for_line(linenumb):\n  run_cmd = ' '.join(['!tools\/autotest.py', '-C', path_to_build_dir(), '%',\n                      '--line', linenumb] )\n  vim.command(run_cmd)\n<\/span><span class=\"no\">endpython\n\n<\/span>fun! RunTestForCurrentLine<span class=\"o\">()<\/span>\n  <span class=\"nb\">let <\/span>l:current_line <span class=\"o\">=<\/span> shellescape<span class=\"o\">(<\/span>line<span class=\"o\">(<\/span><span class=\"s1\">'.'<\/span><span class=\"o\">))<\/span>\n  pythonx run_test_for_line<span class=\"o\">(<\/span>vim.eval<span class=\"o\">(<\/span><span class=\"s1\">'l:current_line'<\/span><span class=\"o\">))<\/span>\nendfun\n\nmap &lt;C-T&gt; :call RunTestForCurrentLine<span class=\"o\">()<\/span>&lt;CR&gt;\n<\/code><\/pre><\/div><\/div>\n\n<p>Place the cursor on what we want to test and <code class=\"language-plaintext highlighter-rouge\">ctrl-t<\/code> \u2026 Here you go.\n<img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/autotest.gif\" alt=\"autotest\" \/><\/p>\n\n<h3 id=\"youcompleteme\">YouCompleteMe<\/h3>\n\n<p><a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/vim\">tools\/vim<\/a> has an example configuration for <a href=\"https:\/\/github.com\/ycm-core\/YouCompleteMe\">YouCompleteMe<\/a> (a code\ncompletion engine for Vim). See <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:tools\/vim\/chromium.ycm_extra_conf.py\">tools\/vim\/chromium.ycm_extra_conf.py<\/a>.<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">let <\/span>g:ycm_extra_conf_globlist <span class=\"o\">=<\/span> <span class=\"o\">[<\/span><span class=\"s1\">'..\/.ycm_extra_conf.py'<\/span><span class=\"o\">]<\/span>\n<span class=\"nb\">let <\/span>g:ycm_goto_buffer_command <span class=\"o\">=<\/span> <span class=\"s1\">'split-or-existing-window'<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>As you already know, YouCompleteMe requires clangd. Very fortunately, Chromium\nalready supports clangd and remote index server to get daily index snapshots.<\/p>\n\n<p>Do not skip documents about <a href=\"https:\/\/chromium.googlesource.com\/chromium\/src.git\/+\/HEAD\/docs\/clangd.md\">using Clangd to build chromium<\/a> and <a href=\"https:\/\/linux.clangd-index.chromium.org\/\">chromium\nremote index server<\/a>.<\/p>\n\n<p>Here are short demos for completion suggestions,\n<img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/ycm_auto.gif\" alt=\"ycm_auto\" \/><\/p>\n\n<p>and code jumping(<code class=\"language-plaintext highlighter-rouge\">:YcmCompleter GoTo<\/code>, <code class=\"language-plaintext highlighter-rouge\">:YcmCompleter GoToReferences<\/code>) during\nChromium development.\n<img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/ycm_jump.gif\" alt=\"ycm_jump\" \/><\/p>\n\n<h2 id=\"commenter\">Commenter<\/h2>\n\n<p>A good developer writes good comments, so being a good commenter makes you a\ngood developer (joke). In my humble opinion, <a href=\"https:\/\/github.com\/preservim\/nerdcommenter\">NERD commenter<\/a> will make you a\ngood developer (joke again). You can get all details from the docs of NERD\ncommenter, and Chromium needs only an additional option for mojom.<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">let <\/span>g:NERDCustomDelimiters <span class=\"o\">=<\/span> <span class=\"o\">{<\/span> <span class=\"s1\">'mojom'<\/span>: <span class=\"o\">{<\/span><span class=\"s1\">'left'<\/span>: <span class=\"s1\">'\/\/'<\/span><span class=\"o\">}<\/span> <span class=\"o\">}<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<h2 id=\"file-navigation\">File Navigation<\/h2>\n\n<p>Chromium is really huge, so we benefit from efficient file navigation tools.\nThere are lots of awesome fuzzy finder plugins for this purpose and I have been\nusing <a href=\"https:\/\/github.com\/wincent\/command-t\">command-t<\/a> for a long time. But command-t requires a Vim executable\nwith ruby\/lua support or Neovim. If you need a simpler yet still powerful\nnavigator, <a href=\"https:\/\/github.com\/junegunn\/fzf\">fzf.vim<\/a> is an altenative great option.<\/p>\n\n<p>Since Chromium a git project, search commands based by <code class=\"language-plaintext highlighter-rouge\">git ls-files<\/code> will\nprovide results very quickly. Use the option <code class=\"language-plaintext highlighter-rouge\">let g:CommandTFileScanner = 'git'<\/code>\nfor <code class=\"language-plaintext highlighter-rouge\">command-t<\/code>, and use the command <code class=\"language-plaintext highlighter-rouge\">:GFiles<\/code> for <code class=\"language-plaintext highlighter-rouge\">fzf.vim<\/code>.<\/p>\n\n<p><img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/filenav.gif\" alt=\"filenav\" \/><\/p>\n\n<p>In case you can\u2019t depend on <code class=\"language-plaintext highlighter-rouge\">git ls-files<\/code> based commands, please make sure your\nplugin use <code class=\"language-plaintext highlighter-rouge\">rg<\/code> or <code class=\"language-plaintext highlighter-rouge\">fd<\/code> which are the fastest command line search tools. For\nexample, <a href=\"https:\/\/github.com\/junegunn\/fzf\">fzf.vim<\/a> has an option <code class=\"language-plaintext highlighter-rouge\">FZF_DEFAULT_COMMAND<\/code> and the following\nsuggestion in the manual: <code class=\"language-plaintext highlighter-rouge\">export FZF_DEFAULT_COMMAND='fd --type f'<\/code>.<\/p>\n\n<h2 id=\"conclusion\">Conclusion<\/h2>\n\n<p>Thanks for reading and I hope this blog post can be some help to your\ndevelopment enviroment for Chromium. Any comment for sharing some other cool\ntips always be welcomed, so that we can make our Vim more productive. (Right,\nthis is the real purpose of this blog post.)<\/p>\n\n<p>\u2026. I will be back someday with debugging Chromium in Vim.\n<img src=\"\/assets\/posts\/tips-for-using-vim-when-developing-chromium\/back.png\" alt=\"sneak peek\" \/><\/p>\n\n","pubDate":"Mon, 30 Jan 2023 02:14:00 +0000","link":"https:\/\/duswnchl.github.io\/posts\/tips-for-using-vim-when-developing-chromium\/","guid":"https:\/\/duswnchl.github.io\/posts\/tips-for-using-vim-when-developing-chromium\/","category":["chromium","vim","igalia-planet","dev"]}]}}