Prechádzať zdrojové kódy

Simple tutorial for vscode config (#94)

* add_cxxflags examples

* Revert "add_cxxflags examples"

This reverts commit 1b5fd0173ae4fa2dfa590e6aedfce61fb1bdff7d.

* add_cxxflags examples

* command "ccache" to "cache"

* Use xmake in vscode

Simple vscode tutorial
Maxwell Geng 3 rokov pred
rodič
commit
dfcea43561

+ 1 - 0
_sidebar.md

@@ -15,6 +15,7 @@
   - [Project Examples](guide/project_examples.md)
   - [Configuration](guide/configuration.md)
   - [Syntax Description](guide/syntax_description.md)
+  - [Use xmake in VSCode](guide/use_in_vscode.md)
   - [FAQ](guide/faq.md)
 
 - Package Management

BIN
assets/img/guide/vscode_status_bar.png


+ 64 - 0
guide/use_in_vscode.md

@@ -0,0 +1,64 @@
+
+[VSCode](https://code.visualstudio.com/)is a commonly used text editor, and xmake provides plug-ins' support.
+
+## Plugin installation
+
+Since VSCode itself only provides text editing functions, we need to install plug-ins to support configuration, compilation, debugging, intellisenses and other functions:
+
+* XMake
+* C/C++
+* CodeLLDB
+
+After completing the installation of the plug-in, restart VSCode to see the status bar below:
+
+![](/assets/img/guide/vscode_status_bar.png)
+
+You can set the platform, architecture, compilation mode, tool-chain and other options in the status bar, and then click Build to start the build.
+
+## Custom options
+
+If these options are not enough, you can create .vscode/settings.json and write the settings required by xmake, such as:
+
+```
+{
+...
+  "xmake.additionalConfigArguments": [
+    "--my_option=true"
+  ],
+...
+}
+```
+
+Other xmake options can also be setted in settings.json. After modification, the configuration can be refreshed through the >XMake: Configure command.
+
+## Improve the development experience with LSP
+
+For a better C++ intellisense experience, xmake provides support for [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) (LSP for short). In vscode, you can use the >XMake: UpdateIntellisense command to generate .vscode/compile_commands.json (usually when modifying xmake.lua, this file will be generated automatically). At the same time, we can choose to install a intellisense plug-in that supports LSP, such as [clangd](https://clangd.llvm.org/) published by LLVM, which is stable and efficient, and support different tool-chain through the LSP standard.
+
+When using clangd, there may be conflicts with the C/C++ plug-in, you can add settings in .vscode/settings.json: 
+
+```
+{
+  "C_Cpp.codeAnalysis.runAutomatically": false,
+  "C_Cpp.intelliSenseEngine": "Disabled",
+  "C_Cpp.formatting": "Disabled",
+  "C_Cpp.autoAddFileAssociations": false,
+  "C_Cpp.autocompleteAddParentheses": false,
+  "C_Cpp.autocomplete": "Disabled",
+  "C_Cpp.errorSquiggles": "Disabled",
+...
+}
+```
+
+Also, since the compile_commands.json generated by XMake is in the .vscode directory, you need to set the clangd parameter to look for it in the correct location: 
+
+```
+{
+  "clangd.arguments": [
+    "--compile-commands-dir=.vscode",
+...
+  ]
+...
+}
+```
+

+ 1 - 0
zh-cn/_sidebar.md

@@ -17,6 +17,7 @@
   - [工程例子](zh-cn/guide/project_examples.md)
   - [配置说明](zh-cn/guide/configuration.md)
   - [语法描述](zh-cn/guide/syntax_description.md)
+  - [在VSCode中使用xmake](zh-cn/guide/use_in_vscode.md)
   - [问答](zh-cn/guide/faq.md)
 
 - 包依赖管理

+ 64 - 0
zh-cn/guide/use_in_vscode.md

@@ -0,0 +1,64 @@
+
+[VSCode](https://code.visualstudio.com/)是常用的文本编辑器,xmake提供了插件支持。
+
+## 插件安装
+
+由于VSCode本身只提供了文本编辑的功能,我们需要安装插件以支持配置,编译,调试,语法提示等功能: 
+
+* XMake
+* C/C++
+* CodeLLDB
+
+在完成插件的安装后,重启VSCode可以看到下方的状态栏: 
+
+![](/assets/img/guide/vscode_status_bar.png)
+
+可以在状态栏设置平台,架构,编译模式,工具链等选项,随后点击Build开始构建。
+
+## 自定义选项
+
+如果这些选项不够,可以创建.vscode/settings.json并编写xmake需要的设置,如
+
+```
+{
+...
+  "xmake.additionalConfigArguments": [
+    "--my_option=true"
+  ],
+...
+}
+```
+
+其他xmake的选项也同样可以在settings.json中完成设置。修改后可通过 >XMake: Configure 命令刷新配置。
+
+## 使用LSP提高开发体验
+
+为了更好的C++语法提示体验,xmake提供了对[Language Server Protocol(https://microsoft.github.io/language-server-protocol/)(简称LSP)的支持,在vscode中,可以使用 >XMake: UpdateIntellisense 命令生成.vscode/compile_commands.json(通常在修改xmake.lua时该文件会自动生成)。与此同时,我们可以选择安装支持LSP的语法提示插件,如LLVM推出的[clangd](https://clangd.llvm.org/),其功能稳定且提示流畅,并通过LSP标准完成对不同编译工具链的支持。
+
+使用clangd时,可能与上述的C/C++插件的提示功能有冲突,可以在.vscode/settings.json中添加设置将C/C++的语法提示功能关闭: 
+
+```
+{
+  "C_Cpp.codeAnalysis.runAutomatically": false,
+  "C_Cpp.intelliSenseEngine": "Disabled",
+  "C_Cpp.formatting": "Disabled",
+  "C_Cpp.autoAddFileAssociations": false,
+  "C_Cpp.autocompleteAddParentheses": false,
+  "C_Cpp.autocomplete": "Disabled",
+  "C_Cpp.errorSquiggles": "Disabled",
+...
+}
+```
+
+同时由于XMake生成的compile_commands.json在.vscode目录,还需要设置clangd传参使其在正确位置寻找: 
+
+```
+{
+  "clangd.arguments": [
+    "--compile-commands-dir=.vscode",
+...
+  ]
+...
+}
+```
+