theia介绍及设置相关
# 背景
Theia 是一个可扩展的平台,用于使用最先进的 Web 技术开发成熟的多语言云和桌面 IDE 类产品。
# 范围
- 搭建平台,打造类IDE产品
- 为最终用户提供成熟的多语言 IDE(不仅仅是智能编辑器)
- 同等支持 Cloud IDE 和 Desktop IDE 的范式
- 通过语言和调试服务器协议提供对多种语言的支持
- 使用 javascript UI 库提供现代 GUI
# 版本
基于v1.27.0版本,做二次修改
# [IDE] Language Server Protocol
LSP (opens new window)(Language Server Protocol)是由 redhat, microsoft, codenvy 联合推出的语言服务器协议, 用于编辑器和语言服务器之间的通信。
LSP is a win for both language tooling providers and code editor vendors! LSP创造了编辑器和编程语言的一种双赢局面。
# 协议 & 规范
# 通信协议
编辑器与语言服务器之间,是基于JSON-RPC (opens new window)通信的。
JSON-RPC (opens new window),是一个开源RPC协议,规定了RPC请求,响应,以及请求错误的格式,
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol.
# 语言服务器规范
LSP是一个协议,不是具体的实现,它规定了语言服务器应当实现的一些规范条件, 比如,编码格式,数据结构(Text Documents,Position,Range,Location,……),生命周期(Server lifetime), 以及服务器可支持哪些语言特性(Language Features),例如,completion,hover,definition,codelens等等。
具体的语言服务器,不必支持规范中提到的所有语言特性, 它支持的那部分特性集合,称为语言服务器的能力(Capabilities (opens new window))。
A capability groups a set of language features.
# 环境启动
# Docker部署启动
# 启动
在数据盘创建项目空间目录;
以上做的目的确保服务器安全的同时解决了theia不能创建目录和文件的问题
# cd到数据盘
cd /data && mkdir web-ide
#创建用户组以及用户
#创建用户组
groupadd webide
useradd -d /data/web-ide -s /sbin/nologin -g webide webide
# 授权web-ide目录用户组
chgrp webide web-ide/
# 授权web-ide目录用户
chown webide web-ide/
#要复权限,要不然创建不了文件
chmod 777 /data/web-ide
2
3
4
5
6
7
8
9
10
11
12
13
14
拉取和运行
#theia-full镜像表示他支持多语言版本,当然你也可以使用其它镜像版本。
#docker pull theiaide/theia-full:latest
#创建容器
lsof -i tcp:8765
#docker run -itd --name="web-ide" -p 3000:3000 -v "$(pwd):/home/project:cached" theiaide/theia-full:latest
docker run -itd --name="web-ide-full" -p 8764:3000 -v "/data/web-ide-full:/home/project:cached" theiaide/theia-full:latest
docker pull hackinglab/theia:3.2.0 #当前版本对应theia1.27.0
docker run -itd --name="web-ide" -p 8765:3000 -v "/data/web-ide:/home/project:cached" hackinglab/theia:3.2.0
2
3
4
5
6
7
8
9
10
# 自己打包镜像
可以参考:
# https://hub.docker.com/r/hackinglab/theia
#https://github.com/theia-ide/theia-apps/blob/master/theia-docker/Dockerfile
mkdir /opt/
cd /opt/
git clone https://github.com/theia-ide/theia-apps
cd /opt/theia-apps/theia-docker
docker build --no-cache -t bdp-tech/theia:1.0.0 -t bdp-tech/theia:1.0 -t bdp-tech/theia:latest -f Dockerfile .
2
3
4
5
6
7
8
9
Dockerfile
ARG NODE_VERSION=12.18.3
FROM node:${NODE_VERSION}-alpine
RUN apk add --no-cache make pkgconfig gcc g++ python libx11-dev libxkbfile-dev libsecret-dev
ARG version=latest
WORKDIR /home/theia
ADD $version.package.json ./package.json
ARG GITHUB_TOKEN
RUN yarn --pure-lockfile && \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build && \
yarn theia download:plugins && \
yarn --production && \
yarn autoclean --init && \
echo *.ts >> .yarnclean && \
echo *.ts.map >> .yarnclean && \
echo *.spec.* >> .yarnclean && \
yarn autoclean --force && \
yarn cache clean
FROM node:${NODE_VERSION}-alpine
# See : https://github.com/theia-ide/theia-apps/issues/34
RUN addgroup theia && \
adduser -G theia -s /bin/sh -D theia;
RUN chmod g+rw /home && \
mkdir -p /home/project && \
chown -R theia:theia /home/theia && \
chown -R theia:theia /home/project;
RUN apk add --no-cache git openssh bash libsecret
ENV HOME /home/theia
WORKDIR /home/theia
COPY --from=0 --chown=theia:theia /home/theia /home/theia
EXPOSE 3000
ENV SHELL=/bin/bash \
THEIA_DEFAULT_PLUGINS=local-dir:/home/theia/plugins
ENV USE_LOCAL_GIT true
USER theia
ENTRYPOINT [ "node", "/home/theia/src-gen/backend/main.js", "/home/project", "--hostname=0.0.0.0" ]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 版本要求
- Nodes:
14.19.0
; 用到n
或者nvm
管理; - Yarn:
v1.22.19
# 环境要求
- Node.js
>= 14
- We recommend using Node's LTS: currently 16.x
- If you are interested in Theia's VS Code Extension support then you should use a Node version at least compatible with the one included in the version of Electron used by VS Code (opens new window).
- Yarn package manager (opens new window)
>= 1.7.0
AND< 2.x.x
. - git (If you would like to use the Git-extension too, you will need to have git version 2.11.0 or higher.)
- Python3 is required for the build due to
node-gyp@8.4.1
(opens new window)
Some additional tools and libraries are needed depending on your platform:
- Linux
- make (opens new window)
- gcc (opens new window) (or another compiling toolchain)
- pkg-config (opens new window)
- build-essential:
sudo apt-get install build-essential
native-keymap
native node module dependencies:- Debian-based:
sudo apt-get install libx11-dev libxkbfile-dev
- Red Hat-based:
sudo yum install libX11-devel.x86_64 libxkbfile-devel.x86_64 # or .i686
- FreeBSD:
sudo pkg install libX11
- Debian-based:
keytar
native node module dependencies (reference):- Debian/Ubuntu:
sudo apt-get install libsecret-1-dev
- Red Hat-based:
sudo yum install libsecret-devel
- Arch Linux:
sudo pacman -S libsecret
- Alpine:
apk add libsecret-dev
- Debian/Ubuntu:
- Linux/MacOS
- nvm (opens new window) is recommended to easily switch between Node.js versions.
- Windows
- We recommend using
scoop
(opens new window). The detailed steps are here (opens new window).
- We recommend using
# 源相关设置
../node_modules/.bin/yarn config set registry https://registry.npm.taobao.org/ -g
#设置好几个特殊库
../node_modules/.bin/yarn config set electron_mirror https://npm.taobao.org/mirrors/electron/ -g
../node_modules/.bin/yarn config set puppeteer_download_host https://npm.taobao.org/mirrors/ -g
../node_modules/.bin/yarn config set playwright_download_host https://npm.taobao.org/mirrors/ -g
2
3
4
5
6
启动
git clone https://github.com/eclipse-theia/theia \
&& cd theia \
&& yarn \
&& yarn download:plugins \
&& yarn browser build \
&& yarn browser start
#116上操作
../node_modules/.bin/yarn install
../node_modules/.bin/yarn download:plugins
2
3
4
5
6
7
8
9
10
# 仓库项目结构
Theia repository has multiple folders:
packages
folder contains runtime packages, as the core package and extensions to itdev-packages
folder contains devtime packages- @theia/cli (opens new window) is a command line tool to manage Theia applications
- @theia/ext-scripts (opens new window) is a command line tool to share scripts between Theia runtime packages
examples
folder contains example applications, both Electron-based and browser-baseddoc
folder provides documentation about how Theia worksscripts
folder contains JavaScript scripts used by npm scripts when installing- the root folder lists dev dependencies and wires everything together with Lerna (opens new window)
# Theia CLI
基本命令
命令 | 含义及备注 |
---|---|
theia build --mode development | 开发模式构建 |
theia build | 生成模式构建 |
theia build --watch --mode development | 监听构建 |
theia clean | 清理构建产物 |
theia rebuild | electron 目标模式下开发,回滚 Native 模块,切换到 browser 目标模式下等需要执行该命令 |
theia start | 启动后端服务 |
theia start --inspect | 调试后端服务 |
theia download:plugins | 下载插件 |
# Eclipse Theia 蓝图
Eclipse Theia Blueprint 是一个模板,用于构建基于 Eclipse Theia 平台的基于桌面的产品,以及展示 Eclipse Theia 功能。它由现有 Eclipse Theia 功能和扩展的子集组成,可以轻松下载并安装在所有主要操作系统平台上(见下文)。文档可帮助您定制和构建您自己的基于 Eclipse Theia 的产品。
注意:Eclipse Theia Blueprint 目前处于测试阶段。
# 架构平台分离
在扩展的顶层文件夹中,我们有一个额外的文件夹层来按平台分隔:
- 该
common
文件夹包含不依赖于任何运行时的代码。 - 该
browser
文件夹包含需要现代浏览器作为平台 (DOM API) 的代码。 - 该
electron-browser
文件夹包含需要 DOM API 以及 Electron 渲染器进程特定 API 的前端代码。 - 该
node
文件夹包含需要 Node.js 作为平台的(后端)代码。 - 该
node-electron
文件夹包含特定于 Electron 的(后端)代码。
# centos7安装中碰到的问题
# 依赖问题
g++: 错误:unrecognized command line option ‘-std=c++17’
make: *** [Release/obj.target/onig_scanner/src/onig-result.o] 错误 1
make: 离开目录“/home/samy/work/bdp-ide/node_modules/oniguruma/build”
root@host116[/home/samy/work/bdp-ide]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
#说明
yum install devtoolset-6-gcc-c++ (GCC 6.3.1)
yum install devtoolset-7-gcc-c++ (GCC 7.3.1)
yum install devtoolset-8-gcc-c++ (GCC 8.3.1)
yum install devtoolset-9-gcc-c++ (GCC 9.1.1)
#最后的方案
yum install -y centos-release-scl-rh centos-release-scl
#安装gcc7
yum install -y devtoolset-7-gcc.x86_64 devtoolset-7-gcc-c++.x86_64
#启用
scl enable devtoolset-7 bash
#查看
g++ --version
#修改软连接,防止重启失效
mv /usr/bin/gcc /usr/bin/gcc4.8.5
ln -s /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++4.8.5
ln -s /opt/rh/devtoolset-7/root/usr/bin/g++ /usr/bin/g++
mv /usr/bin/cc /usr/bin/cc4.8.5
ln -s /opt/rh/devtoolset-7/root/usr/bin/cc /usr/bin/cc
mv /usr/bin/c++ /usr/bin/c++4.8.5
ln -s /opt/rh/devtoolset-7/root/usr/bin/c++ /usr/bin/c++
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Playwright依赖问题
@theia/playwright: Failed to install browsers
@theia/playwright: Error: Failed to download Chromium 102.0.5005.40 (playwright build v1005), caused by
@theia/playwright: Error: Download failed: server returned code 404. URL: https://npm.taobao.org/mirrors//builds/chromium/1005/chromium-linux.zip
@theia/playwright: at fulfill.error.error (/home/samy/work/bdp-ide/node_modules/playwright-core/lib/server/registry/download.js:58:21)
@theia/playwright: at ClientRequest.requestCallback (/home/samy/work/bdp-ide/node_modules/playwright-core/lib/common/netUtils.js:81:34)
@theia/playwright: at Object.onceWrapper (events.js:520:26)
@theia/playwright: at ClientRequest.emit (events.js:400:28)
@theia/playwright: at HTTPParser.parserOnIncomingClient (_http_client.js:647:27)
@theia/playwright: at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17)
@theia/playwright: at TLSSocket.socketOnData (_http_client.js:515:22)
@theia/playwright: at TLSSocket.emit (events.js:400:28)
@theia/playwright: at addChunk (internal/streams/readable.js:293:12)
@theia/playwright: at readableAddChunk (internal/streams/readable.js:267:9)
@theia/playwright: at TLSSocket.Readable.push (internal/streams/readable.js:206:10)
@theia/playwright: at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
@theia/playwright: error Command failed with exit code 1.
@theia/playwright: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@theia/playwright: error Command failed with exit code 1.
@theia/playwright: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
lerna ERR! yarn run prepare exited 1 in '@theia/playwright'
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 参考文档
- https://theia-ide.org/docs
- https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md
- https://github.com/eclipse-theia/theia/blob/master/doc/Publishing.md
- 插件应用市场 (opens new window)
- https://www.digitalocean.com/community/tutorials/how-to-set-up-the-eclipse-theia-cloud-ide-platform-on-ubuntu-18-04-quickstart
- https://styfle.dev/projects/awesome-online-ide
- https://www.jianshu.com/p/682a21010310