当前位置: 首页 > 文档资料 > vsCode 使用指南 >

缓存文件

优质
小牛编辑
134浏览
2023-12-01

按照一般app的设计,都是主应用,和用户目录下的缓存文件,把用户自定义的或使用生成的文件都放到缓存文件目录里。鉴于此,我们来找找code.app的缓存文件,或许能发现点有用的东西

可参照 https://code.visualstudio.com/docs/customization/userandworkspace 理解

缓存目录详情

目录是 /Users/sang/Library/Application Support/Code

 Code pwd /Users/sang/Library/Application Support/Code Code tree . -L 2 . ├── DevTools Extensions ├── File System │   ├── 000 │   └── Origins ├── GPUCache │   ├── data_0 │   ├── data_1 │   ├── data_2 │   ├── data_3 │   └── index ├── Local Storage │   ├── chrome-devtools_devtools_0.localstorage │   ├── chrome-devtools_devtools_0.localstorage-journal │   ├── file__0.localstorage │   └── file__0.localstorage-journal ├── QuotaManager ├── QuotaManager-journal ├── User │   ├── keybindings.json │   ├── launch.json │   └── snippets ├── databases │   ├── Databases.db │   └── Databases.db-journal └── storage.json 8 directories, 17 files 

这些文件我们能看懂的就尽量看,看不懂的也无所谓,如果想深度了解里面的机制,还是有必要看看的。

storage.json

storage.json是code.app的核心配置文件,就像npm里的package.json一样。

看一下具体内容

 Code cat storage.json { "updateChannel": "stable", "windowUIState": { "width": 1280, "height": 773, "mode": 1, "x": 0, "y": 23 }, "openedPathsList": { "folders": [], "files": [ "/Users/sang/Library/Application Support/Code/User/snippets/javascript.json", "/Users/sang/workspace/github/vsc-doc/typings/node/node.d.ts", "/Users/sang/workspace/github/vsc-doc", "/Users/sang/workspace/github/vsc/index.js", "/Users/sang/workspace/moa/rate-cache", "/Users/sang/workspace/aircos/aircos-plugins", "/Users/sang/workspace/github/vsc", "/Users/sang/test/go", "/Users/sang/test/go/views" ] }, "theme": "vs", "folderPickerWorkingDir": "/Users/sang/workspace/moa", "lastActiveOpenedPath": "/Users/sang/workspace/github/vsc-doc" }% 

说明

  • updateChannel 应该检查版本更新的设置
  • windowUIState 界面状态,还记得分割编辑窗口吧?
  • openedPathsList 应该是File -> Open Recent里的内容
  • theme 用户配色方案
  • folderPickerWorkingDir 执行command + o 打开的目录
  • lastActiveOpenedPath 最后打开的目录(这个目录是我执行vsc直接打开的)

为什么要了解它呢?

如果你理解了上面的配置起什么作用,那么你是不是可以干很多坏事儿呢?比如

  • 备份
  • 可视化
  • 其他hack

剩下的自己发挥吧

当前用户配置

上面的目录结构基本都可以看懂,对应当前用户来说

├── User │   ├── keybindings.json(用户自定义的快捷键) │   ├── launch.json(调试加载的文件) │   └── snippets 

用户快捷键

比如快捷键

 Code cat User/keybindings.json // Place your key bindings in this file to overwrite the defaults [ { "key": "ctrl+f12", "command": "editor.action.goToDeclaration", "when": "editorTextFocus" }, { "key": "shift+space", "command": "editor.action.triggerSuggest", "when": "editorTextFocus" } ]% 

是不是和我们之前配置的一样?

用户调试加载的文件

User/launch.json 

和上面的是一样的,就不打印了。如果想每次都定义一下的话,可以自己修改,以后对当前用户就是全局的了

snippets

User/snippets是snippets存放位置,比如javascript的定义

User/snippets/javascript.json 

snippets中文是代码片段,是自定义智能提示用的

自定义snippet

 // Place your snippets for JavaScript here. Each snippet is defined under a snippet name and has a prefix, body and // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, ${id} and ${id:label} and ${1:label} for variables. Variables with the same id are connected. // Example: "Print to console": { "prefix": "log", "body": [ "console.log('$1');", "$2" ], "description": "Log output to console" } 

说明:

  • “Print to console” 是智能提示显示的
  • “prefix” 是用户输入的字母,比如本例中输入log自动提示
  • 当用户触发此snippet的时候,会按照"body"里代码生成
  • $1代表光标位置

自己按照上面的方法定义自己的snippets,可以提高很多工作效率哦

下面看一下如何在代码中使用snippet,如图

和vim、nodepad++里的录制宏类似

另外editor.snippetSuggestions默认是bottom,可以改成top

"editor.snippetSuggestions": "top"