天天看點

vscode附錄

文章目錄

    • basecfg
    • kernel
    • application
    • 手動生成 compile_commands.json
  • 附錄
    • A.1 update on find

basecfg

  • remote-ssh
  • highlight-words
    • 高亮功能
  • 配置,/C:/Users/xxx/AppData/Roaming/Code/User/settings.json
    • {
          "workbench.startupEditor": "none",
          "remote.SSH.remotePlatform": {
              "10.106.36.29": "linux",
              "192.168.56.101": "linux"
          },
          "files.autoGuessEncoding": true,
          "editor.rulers": [
              120
          ],
          "C_Cpp.formatting": "vcFormat",
          "workbench.iconTheme": "vscode-icons",
          "editor.minimap.enabled": false,
          "cmake.configureOnOpen": false,
          "editor.cursorStyle": "line-thin",
          "C_Cpp.vcFormat.space.pointerReferenceAlignment": "right",
          "C_Cpp.vcFormat.indent.withinParentheses": "alignToParenthesis",
          "C_Cpp.vcFormat.newLine.beforeElse": false,
          "C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "sameLine",
          "C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
          "C_Cpp.vcFormat.newLine.beforeOpenBrace.lambda": "sameLine",
          "C_Cpp.vcFormat.newLine.beforeOpenBrace.namespace": "sameLine",
          "C_Cpp.vcFormat.newLine.beforeOpenBrace.type": "sameLine",
          "C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true,
          "C_Cpp.vcFormat.space.insertAfterSemicolon": true,
          "C_Cpp.vcFormat.space.withinInitializerListBraces": false,
          "C_Cpp.vcFormat.wrap.preserveBlocks": "never",
          "editor.formatOnSaveMode": "modifications",
          "editor.formatOnType": true,
          "editor.formatOnPaste": true,
          "editor.suggestSelection": "first",
          "json.maxItemsComputed": 20000,
          "C_Cpp.vcFormat.indent.preprocessor": "oneLeft",
          "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
          "editor.bracketPairColorization.enabled": true,
          "editor.fontFamily": "'JetBrains Mono', 'Courier New', monospace",
          "workbench.editor.wrapTabs": true,
          "codesnap.shutterAction": "copy",
          "codesnap.transparentBackground": true,
          "terminal.integrated.defaultProfile.windows": "Command Prompt",
          "vsicons.dontShowNewVersionMessage": true,
          "git.ignoreLegacyWarning": true,
          "workbench.colorTheme": "One Dark Pro"
      }
                 

kernel

  • git clone https://github.com/alexlo2000/vscode-linux-kernel.git .vscode
  • ./.vscode/generate_compdb.py
    • 生成,compile_commands.json

application

  • sudo pip install compiledb
  • compiledb -p compile_log.txt
    • 生成,compile_commands.json
  • 修改.vscode/setting.json
    • {
          "C_Cpp.default.compileCommands": "compile_commands.json"
      }
                 

手動生成 compile_commands.json

gencompilerFile.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import json, os, sys
import subprocess

cmdlist = [
    "find ./drivers/ips -name *.c -o -name *.h",
]

def main(argv):
    tmpdic = {}
    jsondata = []
    with open('compile_commands.json', 'w', encoding='utf8') as wfp:
        for itm in cmdlist:
            raw = subprocess.Popen(itm,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE).communicate()[0].decode().split()
            for sigf in raw:
                ttfile = os.path.split(sigf)
                tmpdic["directory"] = ttfile[0]
                tmpdic["file"] = ttfile[1]
                jsondata.append(tmpdic)
        json.dump(jsondata, wfp, ensure_ascii=False, indent=4, separators=(',', ': '))
    if not os.path.exists(".vscode/setting.json"):
        os.mkdir(".vscode")
        dica = {}
        with open(".vscode/setting.json", 'w', encoding='utf8') as wfp:
            dica["C_Cpp.default.compileCommands"] = "compile_commands.json"
            json.dump(dica, wfp, ensure_ascii=False, indent=4, separators=(',', ': '))

if __name__ == '__main__':
    main(sys.argv)
           

附錄

A.1 update on find

custag.sh

#!/bin/bash

#rm -rf cscope.files cscope.out cscope.in.out cscope.po.out
rdir=$(cd "$(dirname "$0")";pwd)
csfile=${rdir}/cscope.files
rootop=`dirname ${rdir}`

rm -rf ${csfile} ${rootop}/compile_commands.json

array_search=( \
	${rootop}/kmsm4.19/include \
	${rootop}/kmsm4.19/drivers/staging/android \
)

for element in ${array_search[@]}
do
	find ${element} -type f -name "*.c" -o -name "*.cpp" -o -name "*.h" >> ${csfile}
done

echo "cscope add cscope.files"
python3 ${rdir}/tocompiledb.py $csfile

# cscope -Rbq -i cscope.files
# ctags --langmap=c:+.h --languages=c,c++,java --links=yes --c-kinds=+px --c++-kinds=+px --fields=+iaKSz --extra=+q -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ --file-scope=yes --if0=no -R -L cscope.files

           

tocompiledb.py

#!/usr/bin/python3
#-*- coding: utf-8 -*-
# compiledb -p compile_commands.json
# cuscompdb.py
import sys, os, json


if __name__ == '__main__':
	tmpdic = {}
	jsondata = []
	codir=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
	print("to compiledb by", sys.argv[1])
	with open(sys.argv[1], 'r', encoding='utf8') as rfd:
		for itm in rfd.readlines():
			ttfile = os.path.split(itm.strip())
			tmpdic["directory"] = ttfile[0]
			tmpdic["file"] = ttfile[1]
			jsondata.append(tmpdic)
			del ttfile
			tmpdic = {}
			pass
		pass
	# print(jsondata)
	with open(os.path.join(codir, 'compile_commands.json'), 'w', encoding='utf8') as wfp:
		json.dump(jsondata, wfp, ensure_ascii=False, indent=4, separators=(',', ': '))
	pass

           

–end

繼續閱讀