How to use the vscode-languageserver.Files.uriToFilePath function in vscode-languageserver

To help you get started, we’ve selected a few vscode-languageserver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ikappas / vscode-phpcs / phpcs-server / src / linter.ts View on Github external
public async lint(document: TextDocument, settings: PhpcsSettings): Promise {

		// Process linting paths.
		let filePath = Files.uriToFilePath(document.uri);

		// Make sure we capitalize the drive letter in paths on Windows.
		if (filePath !== undefined && /^win/.test(process.platform)) {
			let pathRoot: string = path.parse(filePath).root;
			let noDrivePath = filePath.slice(Math.max(pathRoot.length - 1, 0));
			filePath = path.join(pathRoot.toUpperCase(), noDrivePath);
		}

		let fileText = document.getText();

		// Return empty on empty text.
		if (fileText === '') {
			return [];
		}

		// Process linting arguments.
github SPGoding / datapack-language-server / src / server.ts View on Github external
connection.onInitialize(async ({ workspaceFolders }) => {
    const completionTriggerCharacters = [' ', ',', '{', '[', '=', ':', '/', '!', "'", '"', '.', '@']
    const completionCommitCharacters = [...completionTriggerCharacters, '}', ']']
    if (workspaceFolders) {
        workspaceFolder = workspaceFolders[0]
        workspaceFolderPath = Files.uriToFilePath(workspaceFolder.uri) as string
        connection.console.info(`workspaceFolderPath = ${workspaceFolderPath}`)

        dotPath = path.join(workspaceFolderPath as string, '.datapack')
        cachePath = path.join(dotPath, 'cache.json')
        dataPath = path.join(workspaceFolderPath as string, 'data')

        connection.console.info(`dotPath = ${dotPath}`)
        connection.console.info(`cachePath = ${cachePath}`)
        connection.console.info(`dataPath = ${dataPath}`)
        if (!fs.pathExistsSync(dotPath)) {
            fs.mkdirpSync(dotPath)
        }
        if (fs.existsSync(cachePath)) {
            cacheFile = await fs.readJson(cachePath, { encoding: 'utf8' })
            if (cacheFile.version !== LatestCacheFileVersion) {
                cacheFile = { cache: {}, files: {}, version: LatestCacheFileVersion }
github willowtreeapps / hinoki / src / validateDocument.ts View on Github external
export default function validateDocument(document: TextDocument): Diagnostic[] {
    const diagnostics: Diagnostic[] = [],
        contents = document.getText(),
        filePath = Files.uriToFilePath(document.uri),
        cliEngine = new wist.CLIEngine(),
        report: Report = cliEngine.executeOnText(contents, filePath);

    if (report && report.results && Array.isArray(report.results) && report.results.length > 0) {
        const docReport = report.results[0];

        if (docReport.messages && Array.isArray(docReport.messages)) {
            docReport.messages.forEach((problem) => {
                if (problem) {
                    const diagnostic = makeDiagnostic(problem);
                    diagnostics.push(diagnostic);
                }
            });
        }
    }
github schneiderpat / aspnet-helper / aspnet-helper-server / src / features / model / declarationInfo.ts View on Github external
private getViewImportsFiles(): string[] {
        let currentDir = Files.uriToFilePath(this._document.uri);
        if (!currentDir) return [];        
        
        let files: string[] = [];
        while (currentDir !== this._rootDir) {
            currentDir = path.dirname(currentDir);
            fs.readdirSync(currentDir).forEach(f => {
                if (f.includes('_ViewImports.cshtml')) files.push(currentDir + path.sep + f);
            });
        }

        return files;
    }
github schneiderpat / aspnet-helper / aspnet-helper-server / src / features / model / declarationInfo.ts View on Github external
private getRootPath() {
        let currentDir = Files.uriToFilePath(this._document.uri);
        if (!currentDir) return
        while (currentDir !== this._rootDir) {
            currentDir = path.dirname(currentDir);
            fs.readdirSync(currentDir).forEach(f => {
                if (f.includes('project.json') || f.includes('csproj')) {
                    if (currentDir) this._rootDir = currentDir;
                    return;
                } 
            });
        }
    }
github schneiderpat / aspnet-helper / aspnet-helper-server / src / features / tagHelper / declarationInfo.ts View on Github external
private getRootPath() {
        let currentDir = Files.uriToFilePath(this._document.uri);

        while (currentDir !== this._rootDir) {
            currentDir = path.dirname(currentDir);
            fs.readdirSync(currentDir).forEach(f => {
                if (f.includes('project.json') || f.includes('csproj')) {
                    this._rootDir = currentDir;
                    return;
                } 
            });
        }
    }
github mrmlnc / vscode-doiuse / src / server.ts View on Github external
function doValidate(document: TextDocument): any {
	const uri = document.uri;
	const content: string = document.getText();
	const diagnostics = [];

	const lang: string = document.languageId;
	const syntax = getSyntax(lang);

	if (editorSettings.ignoreFiles.length) {
		let fsPath: string = Files.uriToFilePath(uri);
		if (workspaceFolder) {
			fsPath = path.relative(workspaceFolder, fsPath);
		}

		const match = micromatch([fsPath], editorSettings.ignoreFiles);
		if (editorSettings.ignoreFiles && match.length !== 0) {
			return diagnostics;
		}
	}

	const linterOptions = {
		browsers: editorSettings.browsers,
		ignore: editorSettings.ignore,
		onFeatureUsage: (usageInfo) => diagnostics.push(makeDiagnostic(usageInfo))
	};
github schneiderpat / aspnet-helper / aspnet-helper-server / src / features / tagHelper / declarationInfo.ts View on Github external
public getCurrentController(): string {
        let folderNameRegExp = new RegExp('.*\\' + path.sep + '([a-zA-Z]+)$');
        let name = folderNameRegExp.exec(path.dirname(Files.uriToFilePath(this._document.uri)));
        if (name) return name[1]
        return '';
    }
github SPGoding / datapack-language-server / src / server.ts View on Github external
function getRelFromUri(uri: string) {
    const abs = Files.uriToFilePath(uri) as string
    if (workspaceFolderPath) {
        return path.relative(workspaceFolderPath, abs)
    }
    return abs
}