Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime): add ts lsp server #1660

Merged
merged 16 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtimes/nodejs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY . /app
# COPY --chown=node:node . /app
RUN mkdir /app/data || true
RUN chown node:node /app/data
RUN chown node:node /app/functions
# RUN npm install
# RUN npm run build
RUN chown -R node:node /app/node_modules
Expand Down
1 change: 0 additions & 1 deletion runtimes/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Intro

`runtime-nodejs` is the application service engine of `laf`, responsible for:
Expand Down
79 changes: 79 additions & 0 deletions runtimes/nodejs/functions/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* The input parameters of cloud function calls
*/
declare interface FunctionContext {
__function_name: string

/**
* This object is parsed from JWT Token Payload
*/
user?: {
[key: string]: any
}

/**
* Uploaded file, the file object array
*/
files?: File[]

/**
* HTTP headers
*/
headers?: IncomingHttpHeaders

/**
* HTTP Query parameter (URL parameter), JSON object
*/
query?: any

/**
* HTTP Body
*/
body?: any

/**
*
*/
params?: any

/**
* HTTP Request ID
*/
requestId?: string

/**
* HTTP Method
*/
method?: string

/**
* Express request object
*/
request?: HttpRequest

/**
* Express response object
*/
response?: HttpResponse

/**
* WebSocket object
*/
socket?: WebSocket

[key: string]: any
}

interface IModule {
exports: any
}

interface IProcess {
/**
* Environment
*/
env: any
}

declare const module: IModule
declare const process: IProcess
14 changes: 14 additions & 0 deletions runtimes/nodejs/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noUnusedLocals": false,
"noUnusedParameters": false,
"baseUrl": "./",
"paths": {
"@/*": ["./*"]
}
},
"include": [
"./*"
]
}
84 changes: 84 additions & 0 deletions runtimes/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion runtimes/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"node-modules-utils": "^1.0.0-beta.14",
"nodemailer": "^6.6.3",
"pako": "^2.1.0",
"typescript-language-server": "^3.3.2",
"validator": "^13.7.0",
"vscode-languageserver": "^9.0.1",
"vscode-ws-jsonrpc-cjs": "^3.0.0",
"ws": "^8.11.0",
"zlib": "^1.0.5"
},
Expand Down Expand Up @@ -83,4 +86,4 @@
"lint-staged": {
"*.{ts,js}": "eslint --fix"
}
}
}
12 changes: 7 additions & 5 deletions runtimes/nodejs/src/handler/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const nodeModulesRoot = path.resolve(__dirname, '../../node_modules')
* Gets declaration files of a dependency package
*/
export async function handlePackageTypings(req: IRequest, res: Response) {

// verify the debug token
const token = req.get('x-laf-develop-token')
if (!token) {
Expand Down Expand Up @@ -87,9 +86,12 @@ export async function handlePackageTypings(req: IRequest, res: Response) {
}
}



async function getThreePartyPackageTypings(req: IRequest, res: Response, basePath: string, packageName: string) {
async function getThreePartyPackageTypings(
req: IRequest,
res: Response,
basePath: string,
packageName: string,
) {
const requestId = req['requestId']
try {
// Gets other three-party package types
Expand All @@ -106,4 +108,4 @@ async function getThreePartyPackageTypings(req: IRequest, res: Response, basePat
error: error.toString(),
})
}
}
}
9 changes: 9 additions & 0 deletions runtimes/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import xmlparser from 'express-xml-bodyparser'
import './support/cloud-sdk'
import storageServer from './storage-server'
import { DatabaseChangeStream } from './support/database-change-stream'
import url from 'url'

import { LspWebSocket } from './support/lsp'
import { createCloudSdk } from './support/cloud-sdk'

// hack: set createCloudSdk to global object to make it available in @lafjs/cloud package
Expand Down Expand Up @@ -97,6 +100,12 @@ const server = app.listen(Config.PORT, () =>
* WebSocket upgrade & connect
*/
server.on('upgrade', (req, socket, head) => {
const pathname = req.url ? url.parse(req.url).pathname : undefined
if (pathname === '/_/lsp') {
LspWebSocket.handleUpgrade(req, socket, head)
return
}

WebSocketAgent.server.handleUpgrade(req, socket as any, head, (client) => {
WebSocketAgent.server.emit('connection', client, req)
})
Expand Down
Loading
Loading