Skip to content

Commit

Permalink
fix(exthost/#3268): Part 1 - Fix activation error for dendron extensi…
Browse files Browse the repository at this point in the history
…on (#3289)

__Issue:__ The dendron extension is failing with an activation error:

![image](https://user-images.githubusercontent.com/13532591/111376942-56b95880-865d-11eb-9369-2e21a6378990.png)

__Defect:__ The path being supplied to the extension client via InitData is not a valid folder

__Fix:__ Fix up the `logsLocation` and `logFile` initialization logic. Add a test case covering the guarantee in the VSCode API docs - that the parent directory must exist and be a valid directory.

Related #3268
  • Loading branch information
bryphe authored Mar 17, 2021
1 parent 9b0401f commit c2abe68
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Bug Fixes

- #3289 - Extensions: Fix logs location path provided to extension (related #3268)

### Performance

### Documentation
Expand Down
28 changes: 28 additions & 0 deletions development_extensions/oni-test-extension/extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 path = require("path");

/**
* @param {vscode.ExtensionContext} context
Expand All @@ -13,6 +14,33 @@ function activate(context) {
vscode.window.showInformationMessage(message, [])
}),
);


const pass = () => {
vscode.window.showInformationMessage("PASS", [])
};

const fail = (msg) => {
vscode.window.showInformationMessage("FAIL: " + msg, [])
};

cleanup(
vscode.commands.registerCommand("oni-test.exthost.validateLogPathIsDirectory", () => {
(async () => {
// From docs: https://code.visualstudio.com/api/references/vscode-api#ExtensionContext
// Given path might not exist - but parent directory will exist.
const logPath = path.dirname(context.logUri.path);
const logParentUri = vscode.Uri.file(logPath);
const statResult = await vscode.workspace.fs.stat(logParentUri);

if ((statResult.type & vscode.FileType.Directory) == vscode.FileType.Directory) {
pass()
} else {
fail("Filetype was: " + statResult.type.toString());
}
})();
}),
);
}

// this method is called when your extension is deactivated
Expand Down
3 changes: 2 additions & 1 deletion development_extensions/oni-test-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"vscode": "^1.25.0"
},
"activationEvents": [
"onCommand:oni-test.showMessage"
"onCommand:oni-test.showMessage",
"onCommand:oni-test.exthost.validateLogPathIsDirectory"
],
"main": "./extension.js",
"contributes": {},
Expand Down
46 changes: 46 additions & 0 deletions integration_test/ExtHostContextTest.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
open Oni_Model;
open Oni_IntegrationTestLib;

// This test validates:
// - The 'oni-dev' extension gets activated
// - When typing in an 'oni-dev' buffer, we get some completion results
runTest(~name="ExtHostContextTest", ({dispatch, wait, _}) => {
wait(~timeout=30.0, ~name="Exthost is initialized", (state: State.t) =>
Feature_Exthost.isInitialized(state.exthost)
);

// Wait until the extension is activated
// Give some time for the exthost to start
wait(
~timeout=30.0,
~name="Validate the 'oni-dev' extension gets activated",
(state: State.t) =>
List.exists(
id => id == "oni-dev-extension",
state.extensions |> Feature_Extensions.activatedIds,
)
);

// Kick off an oni-test command that should activate the oni-test-extension:
dispatch(
Actions.Extensions(
Feature_Extensions.Msg.command(
~command="oni-test.exthost.validateLogPathIsDirectory",
~arguments=[],
),
),
);

// Validate test passes
wait(
~timeout=30.0,
~name="Validate test passes",
(state: State.t) => {
let notifications = Feature_Notification.all(state.notifications);
notifications
|> List.exists((notification: Feature_Notification.notification) => {
notification.message == "PASS"
});
},
);
});
4 changes: 2 additions & 2 deletions integration_test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ConfigurationInvalidThemeTest ConfigurationPerFileTypeTest
EditorFontFromPathTest EditorFontValidTest EditorSplitFileTest
EditorUtf8Test ExCommandKeybindingTest ExCommandKeybindingWithArgsTest
ExCommandKeybindingNormTest ExtConfigurationChangedTest
ExCommandKeybindingNormTest ExtConfigurationChangedTest ExtHostContextTest
ExtHostBufferOpenTest ExtHostBufferUpdatesTest
ExtHostCommandActivationTest ExtHostCompletionTest ExtHostDefinitionTest
ExtHostWorkspaceSearchTest FileWatcherTest FormatOnSaveTest
Expand Down Expand Up @@ -44,7 +44,7 @@
ExCommandKeybindingNormTest.exe ExCommandKeybindingWithArgsTest.exe
ExtConfigurationChangedTest.exe ExtHostBufferOpenTest.exe
ExtHostBufferUpdatesTest.exe ExtHostCommandActivationTest.exe
ExtHostCompletionTest.exe ExtHostDefinitionTest.exe
ExtHostContextTest.exe ExtHostCompletionTest.exe ExtHostDefinitionTest.exe
ExtHostWorkspaceSearchTest.exe FileWatcherTest.exe FormatOnSaveTest.exe
KeybindingsInvalidJsonTest.exe KeySequenceJJTest.exe InputIgnoreTest.exe
InputContextKeysTest.exe InputRemapMotionTest.exe LanguageCssTest.exe
Expand Down
4 changes: 2 additions & 2 deletions src/Store/ExtensionClient.re
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ let create =

let tempDir = Filename.get_temp_dir_name();

let logFile = tempDir |> Uri.fromPath;
let logsLocation =
let logsLocation = tempDir |> Uri.fromPath;
let logFile =
Filename.temp_file(~temp_dir=tempDir, "onivim2", "exthost.log")
|> Uri.fromPath;

Expand Down

0 comments on commit c2abe68

Please sign in to comment.