Example #1
0
 getGlobalPackageManagerPath(packageManager) {
     this.trace(`Begin - Resolve Global Package Manager Path for: ${packageManager}`);
     if (!packageManager) {
         packageManager = 'npm';
     }
     if (!this.globalPackageManagerPath.has(packageManager)) {
         let path;
         if (packageManager === 'npm') {
             path = server.Files.resolveGlobalNodePath(this.trace);
         }
         else if (packageManager === 'yarn') {
             path = server.Files.resolveGlobalYarnPath(this.trace);
         }
         this.globalPackageManagerPath.set(packageManager, path);
     }
     this.trace(`Done - Resolve Global Package Manager Path for: ${packageManager}`);
     return this.globalPackageManagerPath.get(packageManager);
 }
Example #2
0
 return server.Files.resolveModule(rootPath, 'jscs').then(function (value) {
     linter = value;
     return server.Files.resolveModule(rootPath, 'jscs/lib/cli-config').then(function (value) {
         configLib = value;
         return { capabilities: { textDocumentSync: documents.syncKind } };
     }, function (error) {
         return Promise.reject(new server.ResponseError(99, 'Failed to load jscs/lib/cli-config library. Please install jscs in your workspace folder using \'npm install jscs\' and then press Retry.', { retry: true }));
     });
 }, function (error) {
Example #3
0
documents.onDidOpen((event) => {
    if (!supportedLanguages[event.document.languageId] || isGitIndex(event.document)) {
        return;
    }
    if (!document2Library[event.document.uri]) {
        let uri = vscode_uri_1.default.parse(event.document.uri);
        let promise;
        if (uri.scheme === 'file') {
            let file = uri.fsPath;
            let directory = path.dirname(file);
            if (nodePath) {
                promise = vscode_languageserver_1.Files.resolve('eslint', nodePath, nodePath, trace).then(undefined, () => {
                    return vscode_languageserver_1.Files.resolve('eslint', globalNodePath, directory, trace);
                });
            }
            else {
                promise = vscode_languageserver_1.Files.resolve('eslint', globalNodePath, directory, trace);
            }
        }
        else {
            promise = vscode_languageserver_1.Files.resolve('eslint', globalNodePath, workspaceRoot, trace);
        }
        document2Library[event.document.uri] = promise.then((path) => {
            let library = path2Library[path];
            if (!library) {
                library = require(path);
                if (!library.CLIEngine) {
                    throw new Error(`The eslint library doesn\'t export a CLIEngine. You need at least eslint@1.0.0`);
                }
                connection.console.info(`ESLint library loaded from: ${path}`);
                path2Library[path] = library;
            }
            return library;
        }, () => {
            connection.sendRequest(NoESLintLibraryRequest.type, { source: { uri: event.document.uri } });
            return null;
        });
    }
    if (settings.eslint.run === 'onSave') {
        validateSingle(event.document);
    }
});
Example #4
0
function resolveModule(moduleName, nodePath, tracer) {
    return vscode_languageserver_1.Files.resolve(moduleName, nodePath, nodePath, tracer).then(modulePath => {
        const _module = require(modulePath);
        if (tracer) {
            tracer(`Module '${moduleName}' loaded from: ${modulePath}`);
        }
        return _module;
    }, error => {
        return Promise.reject(new Error(`Couldn't find module '${moduleName}' in path '${nodePath}'.`));
    });
}
Example #5
0
function getMessage(err, document) {
    var result = null;
    if (typeof err.message === 'string' || err.message instanceof String) {
        result = err.message;
        result = result.replace(/\r?\n/g, ' ');
    }
    else {
        result = "An unknown error occured while validating file: " + server.Files.uriToFilePath(document.uri);
    }
    return result;
}
Example #6
0
function globalYarnPath() {
    if (_globalYarnPath === void 0) {
        _globalYarnPath = vscode_languageserver_1.Files.resolveGlobalYarnPath(trace);
        if (_globalYarnPath === void 0) {
            _globalYarnPath = null;
        }
    }
    if (_globalYarnPath === null) {
        return undefined;
    }
    return _globalYarnPath;
}
Example #7
0
connection.onInitialize(function (params) {
    var rootPath = params.rootPath;
    return vscode_languageserver_1.Files.resolveModule(rootPath, 'eslint').then(function (value) {
        if (!value.CLIEngine) {
            return new vscode_languageserver_1.ResponseError(99, 'The eslint library doesn\'t export a CLIEngine. You need at least eslint@1.0.0', { retry: false });
        }
        lib = value;
        var result = { capabilities: { textDocumentSync: documents.syncKind, codeActionProvider: true } };
        return result;
    }, function (error) {
        return Promise.reject(new vscode_languageserver_1.ResponseError(99, 'Failed to load eslint library. Please install eslint in your workspace folder using \'npm install eslint\' or globally using \'npm install -g eslint\' and then press Retry.', { retry: true }));
    });
});
Example #8
0
connection.onInitialize((params) => {
    let initOptions = params.initializationOptions;
    workspaceRoot = params.rootPath;
    nodePath = initOptions.nodePath;
    globalNodePath = vscode_languageserver_1.Files.resolveGlobalNodePath();
    return {
        capabilities: {
            textDocumentSync: vscode_languageserver_1.TextDocumentSyncKind.None,
            executeCommandProvider: {
                commands: [CommandIds.applySingleFix, CommandIds.applySameFixes, CommandIds.applyAllFixes, CommandIds.applyAutoFix]
            }
        }
    };
});
Example #9
0
function validate(document) {
    try {
        var checker = new linter();
        var fileContents = document.getText();
        var uri = document.uri;
        var fsPath = server.Files.uriToFilePath(uri);
        var config = getConfiguration(fsPath);
        if (!config && settings.jscs.disableIfNoConfig) {
            return;
        }
        if (settings.jscs.configuration) {
            options = settings.jscs.configuration;
        }
        else if (settings.jscs.preset) {
            options = {
                "preset": settings.jscs.preset
            };
        }
        else {
            // TODO provide some sort of warning that there is no config
            // use jquery by default
            options = { "preset": "jquery" };
        }
        // configure jscs module
        checker.registerDefaultRules();
        checker.configure(config || options);
        var diagnostics_1 = [];
        var results = checker.checkString(fileContents);
        var errors = results.getErrorList();
        // test for checker.maxErrorsExceeded();
        if (errors.length > 0) {
            errors.forEach(function (e) {
                diagnostics_1.push(makeDiagnostic(e));
            });
        }
        //return connection.sendDiagnostics({ uri, diagnostics });
        connection.sendDiagnostics({ uri: uri, diagnostics: diagnostics_1 });
    }
    catch (err) {
        var message = null;
        if (typeof err.message === 'string' || err.message instanceof String) {
            message = err.message;
            throw new Error(message);
        }
        throw err;
    }
}
Example #10
0
function validate(document) {
    var CLIEngine = lib.CLIEngine;
    var cli = new CLIEngine(options);
    var content = document.getText();
    var uri = document.uri;
    // Clean previously computed code actions.
    delete codeActions[uri];
    var report = cli.executeOnText(content, vscode_languageserver_1.Files.uriToFilePath(uri));
    var diagnostics = [];
    if (report && report.results && Array.isArray(report.results) && report.results.length > 0) {
        var docReport = report.results[0];
        if (docReport.messages && Array.isArray(docReport.messages)) {
            docReport.messages.forEach(function (problem) {
                if (problem) {
                    var diagnostic = makeDiagnostic(problem);
                    diagnostics.push(diagnostic);
                    recordCodeAction(document, diagnostic, problem);
                }
            });
        }
    }
    // Publish the diagnostics
    return connection.sendDiagnostics({ uri: uri, diagnostics: diagnostics });
}
Example #11
0
function getMessage(err, document) {
    var result = null;
    if (typeof err.message === 'string' || err.message instanceof String) {
        result = err.message;
        result = result.replace(/\r?\n/g, ' ');
        if (/^CLI: /.test(result)) {
            result = result.substr(5);
        }
    }
    else {
        result = "An unknown error occured while validating file: " + vscode_languageserver_1.Files.uriToFilePath(document.uri);
    }
    return result;
}
Example #12
0
 getFileSymbolsCommand(documentSymbolParams) {
     let uri = documentSymbolParams.textDocument.uri;
     return `${this.executable} -o - ${vscode_languageserver_1.Files.uriToFilePath(uri)}`;
 }
Example #13
0
 /**
  * Get the exception message from an exception object.
  *
  * @param exception The exception to parse.
  * @param document The document where the exception occurred.
  * @return string The exception message.
  */
 getExceptionMessage(exception, document) {
     let message = null;
     if (typeof exception.message === 'string' || exception.message instanceof String) {
         message = exception.message;
         message = message.replace(/\r?\n/g, ' ');
         if (/^ERROR: /.test(message)) {
             message = message.substr(5);
         }
     }
     else {
         message = strings.format(strings_1.StringResources.UnknownErrorWhileValidatingTextDocument, vscode_languageserver_1.Files.uriToFilePath(document.uri));
     }
     return message;
 }
Example #14
0
function uriToFilePath(uri) {
    return vscode_languageserver_1.Files.uriToFilePath(uri);
}
Example #15
0
 promise = vscode_languageserver_1.Files.resolve('eslint', nodePath, nodePath, trace).then(undefined, () => {
     return vscode_languageserver_1.Files.resolve('eslint', globalNodePath, directory, trace);
 });