-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from sass/hover
Hover
- Loading branch information
Showing
24 changed files
with
1,748 additions
and
493 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// Docstring. | ||
/// @type String | ||
$from-other: 'hello'; |
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,9 @@ | ||
@use "sass:string" | ||
@use "other" | ||
|
||
$_id: string.unique-id() | ||
$_prefix: other.$from-other | ||
|
||
.card | ||
.body:has(:not(.stuff)) | ||
padding: 4px |
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,69 @@ | ||
const assert = require('node:assert'); | ||
const path = require('node:path'); | ||
const vscode = require('vscode'); | ||
const { showFile, sleepCI } = require('../util'); | ||
|
||
const stylesUri = vscode.Uri.file( | ||
path.resolve(__dirname, 'fixtures', 'styles.sass') | ||
); | ||
|
||
before(async () => { | ||
await showFile(stylesUri); | ||
await sleepCI(); | ||
}); | ||
|
||
after(async () => { | ||
await vscode.commands.executeCommand('workbench.action.closeAllEditors'); | ||
}); | ||
|
||
/** | ||
* @param {import('vscode').Hover[]} hover | ||
* @returns {string} | ||
*/ | ||
function getHoverContents(hover) { | ||
return hover | ||
.flatMap((item) => { | ||
return item.contents.map((content) => | ||
typeof content === 'string' ? content : content.value | ||
); | ||
}) | ||
.join('\n'); | ||
} | ||
|
||
/** | ||
* @param {import('vscode').Uri} documentUri | ||
* @param {import('vscode').Position} position | ||
* @returns {Promise<import('vscode').Hover[]>} | ||
*/ | ||
async function hover(documentUri, position) { | ||
const result = await vscode.commands.executeCommand( | ||
'vscode.executeHoverProvider', | ||
documentUri, | ||
position | ||
); | ||
return result; | ||
} | ||
|
||
test('gets hover information from the same document', async () => { | ||
const result = await hover(stylesUri, new vscode.Position(7, 10)); | ||
|
||
assert.match( | ||
getHoverContents(result), | ||
/\.card \.body:has\(:not\(\.stuff\)\)/ | ||
); | ||
}); | ||
|
||
test('gets hover information from the workspace', async () => { | ||
const result = await hover(stylesUri, new vscode.Position(4, 19)); | ||
|
||
assert.match(getHoverContents(result), /Docstring/); | ||
}); | ||
|
||
test('gets hover information for Sass built-in', async () => { | ||
const result = await hover(stylesUri, new vscode.Position(3, 14)); | ||
|
||
assert.match( | ||
getHoverContents(result), | ||
/Returns a randomly-generated unquoted string/ | ||
); | ||
}); |
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,25 @@ | ||
const path = require('node:path'); | ||
const fs = require('node:fs/promises'); | ||
const vscode = require('vscode'); | ||
const { runMocha } = require('../mocha'); | ||
|
||
/** | ||
* @returns {Promise<void>} | ||
*/ | ||
async function run() { | ||
const filePaths = []; | ||
|
||
const dir = await fs.readdir(__dirname, { withFileTypes: true }); | ||
for (let entry of dir) { | ||
if (entry.isFile() && entry.name.endsWith('test.js')) { | ||
filePaths.push(path.join(entry.parentPath, entry.name)); | ||
} | ||
} | ||
|
||
await runMocha( | ||
filePaths, | ||
vscode.Uri.file(path.resolve(__dirname, 'fixtures', 'styles.sass')) | ||
); | ||
} | ||
|
||
module.exports = { run }; |
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
Oops, something went wrong.