microsoft/vscode-languageserver-node

nodePath not working (vscode-tslint)

maxdeviant opened this issue · 3 comments

You can read the original issues description in vscode-tslint #173.

Whenever I try to set a nodePath for vscode-tslint, it always ends up using the global node_modules path.

You can see that even though the NODE_PATH has a value, it still continues on to call resolveGlobalNodePath.

[Trace - 10:24:16 AM] NODE_PATH value is: c:\Projects\CloudTestGrading\node_modules\@remark\typescript\node_modules
[Trace - 10:24:17 AM] 'npm config get prefix' value is: C:\Program Files\nodejs
[Trace - 10:24:17 AM] NODE_PATH value is: C:\Program Files\nodejs\node_modules

From server/src/files.ts:

export function resolveModulePath(workspaceRoot: string, moduleName: string, nodePath: string, tracer: (message: string, verbose?: string) => void): Thenable<string> {
	if (nodePath) {
		if (!path.isAbsolute(nodePath)) {
			nodePath = path.join(workspaceRoot, nodePath);
		}
		return resolve(moduleName, nodePath, nodePath, tracer).then((value) => {
                        // This line seems to be the culprit
			if (value.indexOf(path.normalize(nodePath)) === 0) {
				return value;
			} else {
				return Promise.reject<string>(new Error(`Failed to load ${moduleName} from node path location.`));
			}
		}).then(undefined, (_error: any) => {
                        // We are passing a custom nodePath that _should_ be valid,
                        // so we do not expect this to be called.
			return resolve(moduleName, resolveGlobalNodePath(tracer), workspaceRoot, tracer);
		});
	} else {
		return resolve(moduleName, resolveGlobalNodePath(tracer), workspaceRoot, tracer);
	}
}
Environment Info:

OS: Windows 7
Node: v7.7.1
VSCode: v1.10.1
vscode-tslint: v0.8.1

I have been trying to assemble a test case to illustrate the problem, but unfortunately there isn't any test coverage for the server code, and it looks like all of the resolve functions are pretty tightly coupled to the outside world.

I fixed this on the server to correctly handling the path comparison.