forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to run css language server headless
- Loading branch information
Showing
22 changed files
with
1,097 additions
and
718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
extensions/css-language-features/client/src/node/cssClientMain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { getNodeFSRequestService } from './nodeFs'; | ||
import { ExtensionContext } from 'vscode'; | ||
import { startClient } from '../cssClient'; | ||
|
||
// this method is called when vs code is activated | ||
export function activate(context: ExtensionContext) { | ||
startClient(context, { fs: getNodeFSRequestService() }); | ||
} |
85 changes: 85 additions & 0 deletions
85
extensions/css-language-features/client/src/node/nodeFs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as fs from 'fs'; | ||
import { Uri } from 'vscode'; | ||
import { getScheme, RequestService, FileType } from '../requests'; | ||
|
||
export function getNodeFSRequestService(): RequestService { | ||
function ensureFileUri(location: string) { | ||
if (getScheme(location) !== 'file') { | ||
throw new Error('fileRequestService can only handle file URLs'); | ||
} | ||
} | ||
return { | ||
getContent(location: string, encoding?: string) { | ||
ensureFileUri(location); | ||
return new Promise((c, e) => { | ||
const uri = Uri.parse(location); | ||
fs.readFile(uri.fsPath, encoding, (err, buf) => { | ||
if (err) { | ||
return e(err); | ||
} | ||
c(buf.toString()); | ||
|
||
}); | ||
}); | ||
}, | ||
stat(location: string) { | ||
ensureFileUri(location); | ||
return new Promise((c, e) => { | ||
const uri = Uri.parse(location); | ||
fs.stat(uri.fsPath, (err, stats) => { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
return c({ type: FileType.Unknown, ctime: -1, mtime: -1, size: -1 }); | ||
} else { | ||
return e(err); | ||
} | ||
} | ||
|
||
let type = FileType.Unknown; | ||
if (stats.isFile()) { | ||
type = FileType.File; | ||
} else if (stats.isDirectory()) { | ||
type = FileType.Directory; | ||
} else if (stats.isSymbolicLink()) { | ||
type = FileType.SymbolicLink; | ||
} | ||
|
||
c({ | ||
type, | ||
ctime: stats.ctime.getTime(), | ||
mtime: stats.mtime.getTime(), | ||
size: stats.size | ||
}); | ||
}); | ||
}); | ||
}, | ||
readDirectory(location: string) { | ||
ensureFileUri(location); | ||
return new Promise((c, e) => { | ||
const path = Uri.parse(location).fsPath; | ||
|
||
fs.readdir(path, { withFileTypes: true }, (err, children) => { | ||
if (err) { | ||
return e(err); | ||
} | ||
c(children.map(stat => { | ||
if (stat.isSymbolicLink()) { | ||
return [stat.name, FileType.SymbolicLink]; | ||
} else if (stat.isDirectory()) { | ||
return [stat.name, FileType.Directory]; | ||
} else if (stat.isFile()) { | ||
return [stat.name, FileType.File]; | ||
} else { | ||
return [stat.name, FileType.Unknown]; | ||
} | ||
})); | ||
}); | ||
}); | ||
} | ||
}; | ||
} |
Oops, something went wrong.