跳转至

开发环境配置

启动参数

/usr/bin/code-server \
    --host=0.0.0.0 --port=8888 \
    --auth none \
    --disable-telemetry \
    --disable-update-check \
    --disable-workspace-trust \
    --disable-file-downloads \
    --app-name='Quant Studio' \
    --welcome-text='Enjoy your quant' \
    --locale=zh-cn

插件源

更换插件源

使用微软的商店源,采用如下的方式

EXTENSIONS_GALLERY='{"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery"}'

插件下载脚本

使用 python request 爬取插件文件

只爬取微软的插件

import json
import time

import requests

lock_meta = []


def write_lock_meta(file_name: str = "-"):
    if file_name == "-":
        file_name = "plugins.lock." + \
            time.strftime('%Y%m%d-%H%M%S', time.localtime(time.time()))
    with open(file_name, 'w+') as write_f:
        write_f.write(json.dumps(lock_meta, indent=4, ensure_ascii=False))


def download_plugin(plugin_meta: dict):
    content = requests.get(plugin_meta['resource_url']).content
    with open("./files/" + plugin_meta['pack_name'], 'wb+') as write_f:
        write_f.write(content)


def get_plugin_meta(plugin_name: str) -> dict:
    print(f"get metadata for plugin {plugin_name}")
    url = "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery"
    headers = {
        'authority': 'marketplace.visualstudio.com',
        'accept': 'application/json;api-version=7.1-preview.1;excludeUrls=true',
        'accept-language': 'zh-CN,zh;q=0.9',
        'content-type': 'application/json',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    }
    payload = json.dumps({
        "assetTypes": None,
        "filters": [
            {
                "criteria": [
                    {
                        "filterType": 7,
                        "value": plugin_name,
                    }
                ],
                "direction": 2,
                "pageSize": 100,
                "pageNumber": 1,
                "sortBy": 0,
                "sortOrder": 0,
                "pagingToken": None
            }
        ],
        "flags": 2151
    })
    response = requests.request("POST", url, headers=headers, data=payload)
    resp = json.loads(response.text)
    latest_version_meta = resp['results'][0]['extensions'][0]['versions'][0]
    version = latest_version_meta['version']
    pack_name = f'{plugin_name.lower()}-{version}.vsix'
    files = latest_version_meta['files']
    resource_url = ''
    for f in files:
        if f['assetType'] == "Microsoft.VisualStudio.Services.VSIXPackage":
            resource_url = f['source']
    return {
        'version': version,
        'pack_name': pack_name,
        'resource_url': resource_url,
    }


def handle_plugins(file_name: str = "./plugins.list") -> None:
    file = open(file_name)
    while True:
        line = file.readline()
        line = line.rstrip()
        if not line:
            break
        meta = get_plugin_meta(line)
        print(f'get meta {meta}')
        lock_meta.append(meta)
        print(f'download plugin {line}')
        download_plugin(meta)
    write_lock_meta()


def main():
    handle_plugins()


if __name__ == "__main__":
    main()

优先爬取 open-vsx 的,如果未找到,则爬取微软的

import json
import time
from typing import Union

import requests

lock_meta = []


def write_lock_meta(file_name: str = "-"):
    if file_name == "-":
        file_name = "plugins.lock." + \
            time.strftime('%Y%m%d-%H%M%S', time.localtime(time.time()))
    with open(file_name, 'w+') as write_f:
        write_f.write(json.dumps(lock_meta, indent=4, ensure_ascii=False))


def download_file(url: str, file_name: str):
    content = requests.get(url).content
    with open(f"./files/{file_name}", 'wb+') as write_f:
        write_f.write(content)


def get_meta_from_open_vsx(plugin_name: str) -> Union[dict, None]:
    print(f"get plugin {plugin_name} metadata from open-vsx")
    url = f"https://open-vsx.org/api/{plugin_name.split('.')[0]}/{plugin_name.split('.')[1]}"
    payload = {}
    headers = {
        'Accept': 'application/json',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
    }
    response = requests.request("GET", url, headers=headers, data=payload)
    resp = json.loads(response.text)
    if not resp.get('version', None):
        print(f"plugin {plugin_name} not found in open-vsx")
        return None
    version = resp['version']
    pack_name = f'{plugin_name.lower()}-{version}.vsix'
    resource_url = resp['files']['download']
    return {
        'version': version,
        'pack_name': pack_name,
        'resource_url': resource_url,
        'src': 'open-vsx',
    }


def get_meta_from_microsoft(plugin_name: str) -> Union[dict, None]:
    print(f"get plugin {plugin_name} metadata from microsoft")
    url = "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery"
    headers = {
        'authority': 'marketplace.visualstudio.com',
        'accept': 'application/json;api-version=7.1-preview.1;excludeUrls=true',
        'accept-language': 'zh-CN,zh;q=0.9',
        'content-type': 'application/json',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    }
    payload = json.dumps({
        "assetTypes": None,
        "filters": [
            {
                "criteria": [
                    {
                        "filterType": 7,
                        "value": plugin_name,
                    }
                ],
                "direction": 2,
                "pageSize": 100,
                "pageNumber": 1,
                "sortBy": 0,
                "sortOrder": 0,
                "pagingToken": None
            }
        ],
        "flags": 2151
    })
    response = requests.request("POST", url, headers=headers, data=payload)
    resp = json.loads(response.text)
    latest_version_meta = resp['results'][0]['extensions'][0]['versions'][0]
    version = latest_version_meta['version']
    pack_name = f'{plugin_name.lower()}-{version}.vsix'
    files = latest_version_meta['files']
    resource_url = ''
    for f in files:
        if f['assetType'] == "Microsoft.VisualStudio.Services.VSIXPackage":
            resource_url = f['source']
    return {
        'version': version,
        'pack_name': pack_name,
        'resource_url': resource_url,
        'src': 'microsoft',
    }


def download_plugin(plugin_name: str):
    # try to download from open-vsx.org
    meta = get_meta_from_open_vsx(plugin_name=plugin_name)
    if not meta:
        meta = get_meta_from_microsoft(plugin_name=plugin_name)
    if isinstance(meta, dict):
        lock_meta.append(meta)
        download_file(meta['resource_url'], meta['pack_name'])
    else:
        print('not found in open-vsx or microsoft')


def handle_plugins(file_name: str = "./plugins.list") -> None:
    file = open(file_name)
    while True:
        line = file.readline().rstrip()
        if not line:
            break
        print(f'download plugin {line}')
        download_plugin(line)
    write_lock_meta()


def main():
    handle_plugins()


if __name__ == "__main__":
    main()

安装和管理插件

Command line extension management
To make it easier to automate and configure VS Code, 

it is possible to list, install, 
and uninstall extensions from the command line. 

When identifying an extension, 
provide the full name of the form publisher.extension, for example ms-python.python.

Set the root path for extensions.
code --extensions-dir 

List the installed extensions.
code --list-extensions

Show versions of installed extensions, when using --list-extension.
code --show-versions

Installs an extension.
code --install-extension ( | )

Uninstalls an extension.
code --uninstall-extension ( | )

Enables proposed API features for extensions. Can receive one or more extension IDs to enable individually.
code --enable-proposed-api ()

插件列表

13xforever.language-x86-64-assembly
aaron-bond.better-comments
abierbaum.vscode-file-peek
abusaidm.html-snippets
adamhartford.vscode-base64
adamwalzer.string-converter
AlanWalk.markdown-toc
alefragnani.Bookmarks
alefragnani.project-manager
alexcvzz.vscode-sqlite
annsk.alignment
bajdzis.vscode-database
bbenoist.shell
bibhasdn.unique-lines
bierner.markdown-checkbox
bierner.markdown-emoji
bierner.markdown-preview-github-styles
brunnerh.insert-unicode
burkeholland.simple-react-snippets
chrisdias.vscode-opennewinstance
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
chrmarti.regex
CoenraadS.bracket-pair-colorizer
cschlosser.doxdocgen
cssho.vscode-svgviewer
d9705996.perl-toolbox
dakara.transformer
darkriszty.markdown-table-prettify
DavidAnson.vscode-markdownlint
dbaeumer.jshint
dbaeumer.vscode-eslint
donjayamanne.githistory
donjayamanne.python-extension-pack
DotJoshJohnson.xml
dsznajder.es7-react-js-snippets
dtsvet.vscode-wasm
eamodio.gitlens
earshinov.permute-lines
ecmel.vscode-html-css
EditorConfig.EditorConfig
EFanZh.graphviz-preview
eg2.vscode-npm-script
eriklynd.json-tools
esbenp.prettier-vscode
everettjf.filter-line
faustinoaq.lex-flex-yacc-bison
fcrespo82.markdown-table-formatter
florianloch.text-transform
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
formulahendry.code-runner
geeklearningio.graphviz-markdown-preview
goessner.mdmath
gogocrow.webpack-snippets
GrapeCity.gc-excelviewer
hdg.live-html-previewer
helixquar.asciidecorator
HookyQR.beautify
HungVo.htext
IBM.output-colorizer
idleberg.emoji-code
James-Yu.latex-workshop
janisdd.vscode-edit-csv
jebbs.plantuml
jeremyrajan.webpack
jerriepelser.copy-markdown-as-html
jkjustjoshing.vscode-text-pastry
jock.svg
kriegalex.vscode-cudacpp
leizongmin.node-module-intellisense
liximomo.sftp
lmcarreiro.vscode-smart-column-indenter
luggage66.AWK
magicstack.MagicPython
maptz.regionfolder
Mebrahtom.plantumlpreviewer
mechatroner.rainbow-csv
mgmcdermott.vscode-language-babel
mhutchie.git-graph
miramac.vscode-exec-node
mitchdenny.ecdc
mohsen1.prettify-json
mrmlnc.vscode-json5
ms-azuretools.vscode-docker
ms-kubernetes-tools.vscode-kubernetes-tools
ms-python.python
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode.cmake-tools
ms-vscode.powershell
ms-vscode.Theme-MarkdownKit
ms-vscode.vscode-typescript-tslint-plugin
msjsdiag.debugger-for-chrome
msjsdiag.vscode-react-native
mtxr.sqltools
numso.prettier-standard-vscode
octref.vscode-json-transform
oijaz.unicode-latex
qcz.text-power-tools
qhoekman.language-plantuml
quicktype.quicktype
redhat.vscode-yaml
RomanPeshkov.vscode-text-tables
ryu1kn.edit-with-shell
ryu1kn.partial-diff
ryu1kn.text-marker
sandcastle.whitespace
sensourceinc.vscode-sql-beautify
shakram02.bash-beautify
shd101wyy.markdown-preview-enhanced
shuworks.vscode-table-formatter
sidthesloth.html5-boilerplate
sidthesloth.svg-snippets
SimonSiefke.svg-preview
sleistner.vscode-fileutils
slevesque.shader
slevesque.vscode-autohotkey
steoates.autoimport
Stephanvs.dot
stkb.rewrap
supakornras.asymptote
technosophos.vscode-helm
twxs.cmake
Tyriar.sort-lines
vincaslt.highlight-matching-tag
VisualStudioExptTeam.vscodeintellicode
vscode-icons-team.vscode-icons
vscoss.vscode-ansible
waderyan.gitblame
whiteout2.x86
wmaurer.join-lines
Wscats.eno
wwm.better-align
xabikos.JavaScriptSnippets
xabikos.ReactSnippets
ybaumes.highlight-trailing-white-spaces
Yog.yog-plantuml-highlight
yzane.markdown-pdf
zeithaste.cursorCharCode
zh9528.file-size
Zignd.html-css-class-completion
zxh404.vscode-proto3