10000 Adds experimental support for running TS Server in a web worker by mjbvz · Pull Request #39656 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Adds experimental support for running TS Server in a web worker #39656

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

Merged
merged 31 commits into from
Dec 9, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e50aedc
Adds experimental support for running TS Server in a web worker
mjbvz Jul 18, 2020
30cb1a6
Shim out directoryExists
mjbvz Jul 23, 2020
fb900a0
Add some regions
mjbvz Aug 31, 2020
4ce8d4a
Remove some inlined note types
mjbvz Aug 31, 2020
94faf66
Use switch case for runtime
mjbvz Aug 31, 2020
f6c0749
Merge branch 'master' into web-worker-server
sheetalkamat Sep 22, 2020
f3178b6
Review and updates
sheetalkamat Sep 23, 2020
6202c51
Enable loading std library d.ts files
mjbvz Sep 25, 2020
b6e8137
Update src/tsserver/webServer.ts
sheetalkamat Sep 28, 2020
dd331e2
Update src/tsserver/webServer.ts
mjbvz Sep 29, 2020
2d4c726
Addressing feedback
mjbvz Sep 29, 2020
69a6523
Allow passing in explicit executingFilePath
mjbvz Sep 29, 2020
5185f6e
Adding logging support
mjbvz Sep 30, 2020
1db3ebc
Do not create auto import provider in partial semantic mode
sheetalkamat Oct 1, 2020
9a1eace
Handle lib files by doing path mapping instead
sheetalkamat Oct 1, 2020
c92d22d
Merge branch 'master' into web-worker-server
sheetalkamat Oct 2, 2020
14498b8
Merge branch 'master' into web-worker-server
sheetalkamat Oct 27, 2020
04a4fe7
TODO
sheetalkamat Oct 27, 2020
b959f3e
Add log message
mjbvz Nov 12, 2020
2359c83
Move code around so that exported functions are set on namespace
sheetalkamat Nov 13, 2020
f29b2e7
Log response
sheetalkamat Nov 13, 2020
0edf650
Map the paths back to https:
sheetalkamat Nov 14, 2020
0820519
If files are not open dont schedule open file project ensure
sheetalkamat Nov 14, 2020
7e49390
Should also check if there are no external projects before skipping s…
sheetalkamat Nov 14, 2020
16ff1ce
Revert "Map the paths back to https:"
sheetalkamat Nov 18, 2020
9952bab
Revert "TODO"
sheetalkamat Nov 18, 2020
2bf35c9
Revert "Should also check if there are no external projects before sk…
sheetalkamat Nov 18, 2020
3c94c98
Merge branch 'master' into web-worker-server
sheetalkamat Nov 21, 2020
542a8b0
Refactoring so we can test the changes out
sheetalkamat Nov 21, 2020
245e49d
Feedback
sheetalkamat Dec 2, 2020
9704738
Merge branch 'master' into web-worker-server
sheetalkamat Dec 2, 2020
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
Prev Previous commit
Next Next commit
Revert "Map the paths back to https:"
This reverts commit 0edf650.
  • Loading branch information
sheetalkamat committed Nov 18, 2020
commit 16ff1ce041fd1dc4f2419c7b9fbba65694a318ea
40 changes: 6 additions & 34 deletions src/tsserver/webServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,12 @@ namespace ts.server {
return typeof cmdLineVerbosity === "undefined" ? nullLogger : new MainProcessLogger(cmdLineVerbosity);
}

interface WebServerHost extends ServerHost {
getWebPath: (path: string) => string | undefined;
}

function createWebSystem(args: string[]) {
Debug.assert(ts.sys === undefined);
const returnEmptyString = () => "";
// Later we could map ^memfs:/ to do something special if we want to enable more functionality like module resolution or something like that
const getWebPath = (path: string) => startsWith(path, directorySeparator) ? path.replace(directorySeparator, executingDirectoryPath) : undefined;
const sys: WebServerHost = {
getWebPath,
const sys: ServerHost = {
args,
newLine: "\r\n", // This can be configured by clients
useCaseSensitiveFileNames: false, // Use false as the default on web since that is the safest option
Expand Down Expand Up @@ -238,8 +233,10 @@ namespace ts.server {
function startWebSession(options: StartSessionOptions, logger: Logger, cancellationToken: ServerCancellationToken) {
class WorkerSession extends Session<{}> {
constructor() {
const host = sys as ServerHost;

super({
host: sys as WebServerHost,
host,
cancellationToken,
...options,
typingsInstaller: nullTypingsInstaller,
Expand All @@ -251,9 +248,6 @@ namespace ts.server {
}

public send(msg: protocol.Message) {
// Updates to file paths
this.updateWebPaths(msg);

if (msg.type === "event" && !this.canUseEvents) {
if (this.logger.hasLevel(LogLevel.verbose)) {
this.logger.info(`Session does not support events: ignored event: ${JSON.stringify(msg)}`);
Expand All @@ -266,30 +260,6 @@ namespace ts.server {
postMessage(msg);
}

private updateWebPaths(obj: any) {
if (isArray(obj)) {
obj.forEach(ele => this.updateWebPaths(ele));
}
else if (typeof obj === "object") {
for (const id in obj) {
if (hasProperty(obj, id)) {
const value = obj[id];
if ((id === "file" || id === "fileName" || id === "renameFilename") && isString(value)) {
const webpath = (sys as WebServerHost).getWebPath(value);
if (webpath) obj[id] = webpath;
}
else if ((id === "files" || id === "fileNames") && isArray(value) && value.every(isString)) {
obj[id] = value.map(ele => (sys as WebServerHost).getWebPath(ele) || ele);
}
else {
this.updateWebPaths(value);
}
}
}

}
}

protected parseMessage(message: {}): protocol.Request {
return <protocol.Request>message;
}
Expand All @@ -309,6 +279,8 @@ namespace ts.server {
this.onMessage(message.data);
});
}

// TODO:: Update all responses to use webPath
}

const session = new WorkerSession();
Expand Down
0