• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #13266

01 Nov 2024 05:58PM UTC coverage: 89.076% (+0.9%) from 88.214%
#13266

push

web-flow
Merge 30be955de into 7cfaaa047

7248 of 8577 branches covered (84.51%)

Branch coverage included in aggregate %.

1095 of 1214 new or added lines in 28 files covered. (90.2%)

24 existing lines in 5 files now uncovered.

9640 of 10382 relevant lines covered (92.85%)

1783.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.33
/src/lsp/worker/WorkerThreadProjectRunner.ts
1
import { setLspLoggerProps } from '../../logging';
1✔
2
import type { LspProject } from '../LspProject';
3
import { Project } from '../Project';
1✔
4
import type { MethodNames, WorkerMessage } from './MessageHandler';
5
import { MessageHandler } from './MessageHandler';
1✔
6
import type { MessagePort } from 'worker_threads';
7

8
/**
9
 * Runner logic for Running a Project in a worker thread.
10
 */
11
export class WorkerThreadProjectRunner {
1✔
12
    //collection of interceptors that will be called when events are fired
NEW
13
    private requestInterceptors = {} as Record<MethodNames<LspProject>, (data: any) => any>;
×
14

15
    private project: Project;
16

17
    private messageHandler: MessageHandler<LspProject>;
18

19
    public run(parentPort: MessagePort) {
20
        //ensure the lgoger is configured for LSP mode
NEW
21
        setLspLoggerProps();
×
22

NEW
23
        this.messageHandler = new MessageHandler({
×
24
            name: 'WorkerThread',
25
            port: parentPort,
26
            onRequest: async (request: WorkerMessage) => {
NEW
27
                try {
×
28
                    //if we have a request interceptor registered for this event, call it
NEW
29
                    this.requestInterceptors[request.name]?.(request.data);
×
30

31
                    //only the LspProject interface method names will be passed as request names, so just call those functions on the Project class directly
NEW
32
                    let responseData = await this.project[request.name](...request.data ?? []);
×
NEW
33
                    this.messageHandler.sendResponse(request, { data: responseData });
×
34

35
                    //we encountered a runtime crash. Pass that error along as the response to this request
36
                } catch (e) {
NEW
37
                    const error: Error = e as any;
×
NEW
38
                    this.messageHandler.sendResponse(request, { error: error });
×
39
                }
40
            },
41
            onUpdate: (update) => {
42

43
            }
44
        });
45

NEW
46
        this.requestInterceptors.activate = this.onActivate.bind(this);
×
47
    }
48

49
    /**
50
     * Fired anytime we get an `activate` request from the client. This allows us to clean up the previous project and make a new one
51
     */
52
    private onActivate() {
53
        //clean up any existing project
NEW
54
        this.project?.dispose();
×
55

56
        //make a new instance of the project (which is the same way we run it in the main thread).
NEW
57
        this.project = new Project();
×
58

NEW
59
        this.project.on('all', (eventName: string, data: any) => {
×
NEW
60
            this.messageHandler.sendUpdate(eventName, {
×
61
                data: data
62
            });
63
        });
64
    }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc