-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(extensions/#2981): Listener function error with 3-param https req…
…uest call (#2995) __Issue:__ The terraform extension was failing with an error: > Error: Activating 'hashicorp terraform' failed: The "listener" argument must be of type function. Received an instance of Object __Defect:__ The extension was crashing here: ``` https.request(url, options, res => { if (res.statusCode === 301 || res.statusCode === 302) { // follow redirects return resolve(httpsRequest(res.headers.location, options, encoding)); } ``` when trying to resolve download locations for terraform releases. This was not specific to this plugin, but actually could crash in any 3-param call to `https.request`. (There are two overloads - a `https.request(options, cb)`, and `https.request(url, options.cb)`. Because of the `agent-base` dependency that is brought in the node environment, it overwrites the `https.request` handler such that only the 2-param overload is accepted. More info here: microsoft/vscode#93167 __Fix:__ Update the `proxyResolver` code to only use the 2-param overload in our node environment, which the extension host is running in - onivim/vscode-exthost#30 . Add some test cases to ensure that both overloads can make requests With this fix, as the language server now gets installed, get some basic language features (diagnostics, some completion, and outline) for terraform files: ![image](https://user-images.githubusercontent.com/13532591/104756239-6b867800-5710-11eb-8aff-cfd082ce0f1b.png) Fixes #2981 Related #1058 Note that there is still a pending issue relating to the syntax highlights for terraform: #2220
- Loading branch information
Showing
6 changed files
with
149 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@onivim/[email protected].1000": | ||
version "1.52.1000" | ||
resolved "https://registry.yarnpkg.com/@onivim/vscode-exthost/-/vscode-exthost-1.52.1000.tgz#f69523da388b9595662ff12c600fe5fe0c2150ae" | ||
integrity sha512-MuW8QfmHPj9q5D37lHdavUZG5cuCanTF8hZ1k/sCGbWKBCVCHPOtQ74pxRFa91t+JCXDTpzXdiW6DBLh+fIjDA== | ||
"@onivim/[email protected].1001": | ||
version "1.52.1001" | ||
resolved "https://registry.yarnpkg.com/@onivim/vscode-exthost/-/vscode-exthost-1.52.1001.tgz#22139888543b604a2babb94c200693290fca4220" | ||
integrity sha512-SbvMucGhnAnz7pwkcuv8sjgOLB8bdldYMm9d/c8Vhgm3yNwtDefsRcvmXyiXidCHRBoKk/ZRvO+9Ua7OiAMV/Q== | ||
dependencies: | ||
graceful-fs "4.2.3" | ||
iconv-lite-umd "0.6.8" | ||
|
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,63 @@ | ||
open TestFramework; | ||
|
||
open Exthost; | ||
|
||
let waitForMessage = (~name, f, context) => { | ||
context | ||
|> Test.waitForMessage( | ||
~name, | ||
fun | ||
| Msg.MessageService(ShowMessage({message, severity, _})) => | ||
f(severity, message) | ||
| _ => false, | ||
); | ||
}; | ||
|
||
describe("HttpRequestTest", ({test, _}) => { | ||
test("Execute a (url, cb) request in extension host", _ => { | ||
Test.startWithExtensions(["oni-http-request"]) | ||
|> Test.waitForExtensionActivation("oni-http-request") | ||
|> Test.withClient( | ||
Request.Commands.executeContributedCommand( | ||
~arguments=[], | ||
~command="http.request2", | ||
), | ||
) | ||
|> waitForMessage( | ||
~name="wait for request result (2-param)", (severity, message) => | ||
switch (severity) { | ||
| Info => true | ||
| Error => | ||
prerr_endline("Got error: " ++ message); | ||
false; | ||
| _ => assert(false) | ||
} | ||
) | ||
|> Test.terminate | ||
|> Test.waitForProcessClosed | ||
}); | ||
|
||
// Regression test for #2981 - ensure 3-param requests work correctly | ||
test("#2981: Execute a (url, options, cb) request in extension host", _ => { | ||
Test.startWithExtensions(["oni-http-request"]) | ||
|> Test.waitForExtensionActivation("oni-http-request") | ||
|> Test.withClient( | ||
Request.Commands.executeContributedCommand( | ||
~arguments=[], | ||
~command="http.request3", | ||
), | ||
) | ||
|> waitForMessage( | ||
~name="wait for request result (3-param)", (severity, message) => | ||
switch (severity) { | ||
| Info => true | ||
| Error => | ||
prerr_endline("Got error: " ++ message); | ||
false; | ||
| _ => assert(false) | ||
} | ||
) | ||
|> Test.terminate | ||
|> Test.waitForProcessClosed | ||
}); | ||
}); |
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,63 @@ | ||
// The module 'vscode' contains the VS Code extensibility API | ||
// Import the module and reference it with the alias vscode in your code below | ||
const vscode = require('vscode'); | ||
const https = require('https'); | ||
|
||
// this method is called when your extension is activated | ||
// your extension is activated the very first time the command is executed | ||
|
||
/** | ||
* @param {vscode.ExtensionContext} context | ||
*/ | ||
function activate(context) { | ||
context.subscriptions.push( | ||
// Execute a 2-parameter request against an https object | ||
vscode.commands.registerCommand('http.request2', (_args) => { | ||
const req = https.request("https://httpbin.org/json", (res) => { | ||
if (res.statusCode == 200) { | ||
vscode.window.showInformationMessage('success'); | ||
} else { | ||
vscode.window.showErrorMessage('Unexpected status code: ' + res.statusCode) | ||
} | ||
}); | ||
|
||
req.on('error', (e) => { | ||
vscode.window.showErrorMessage('Error: ' + e) | ||
}); | ||
|
||
req.end(); | ||
|
||
}) | ||
); | ||
|
||
context.subscriptions.push( | ||
// Execute a 3-parameter request against an https object | ||
// This exercises the same failure that was causing #2981 - | ||
// the [agent-base] NPM package overriding the https.request, | ||
// only handling 2-param arguments. | ||
vscode.commands.registerCommand('http.request3', (_args) => { | ||
const req = https.request("https://httpbin.org/json", { agent: false }, (res) => { | ||
if (res.statusCode == 200) { | ||
vscode.window.showInformationMessage('success'); | ||
} else { | ||
vscode.window.showErrorMessage('Unexpected status code: ' + res.statusCode) | ||
} | ||
}); | ||
|
||
req.on('error', (e) => { | ||
vscode.window.showErrorMessage('Error: ' + e) | ||
}); | ||
|
||
req.end(); | ||
|
||
}) | ||
); | ||
} | ||
|
||
// this method is called when your extension is deactivated | ||
function deactivate() {} | ||
|
||
module.exports = { | ||
activate, | ||
deactivate | ||
} |
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,17 @@ | ||
{ | ||
"name": "oni-http-request", | ||
"description": "HTTP Request extension for Onivim tests", | ||
"version": "0.0.1", | ||
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample", | ||
"engines": { | ||
"vscode": "^1.25.0" | ||
}, | ||
"activationEvents": ["*"], | ||
"main": "./extension.js", | ||
"scripts": { | ||
"postinstall": "node ./node_modules/vscode/bin/install" | ||
}, | ||
"devDependencies": { | ||
"vscode": "^1.1.22" | ||
} | ||
} |