Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prettier script #566

Merged
merged 3 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Create a report to help us improve
title: ''
labels: 'status: needs triage'
assignees: ''

---

<!--
Expand All @@ -16,18 +15,23 @@ When filing an issue, please fill out as much of the information below as you ca
### Your environment

Which OS do you use:

<!-- Windows, MacOS, Ubuntu, ArchLinux, etc... -->

### Steps to reproduce

<!-- Tell us how to reproduce this issue, including screenshots if you think they can be useful -->

### Expected behaviour

<!-- Tell us what should happen. -->

### Actual behaviour

<!-- Tell us what happens instead. -->

### Include debug information

Execute in the root of your project the command `haskell-language-server-wrapper --debug .` and paste the logs here (you can find the executable location [here](https://github.com/haskell/vscode-haskell#downloaded-binaries)):

<details>
Expand All @@ -38,6 +42,7 @@ Debug output:
```
<paste your logs here>
```

</details>

Paste the contents of extension specific log, you can check instructions about how to find it [here](https://github.com/haskell/vscode-haskell#troubleshooting)
Expand All @@ -50,4 +55,5 @@ Extension log:
```
<paste your logs here>
```

</details>
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
uses: haskell/actions/setup@v1
with:
ghc-version: ${{ matrix.ghc }}
- name: "Install `tree` for MacOs"
- name: 'Install `tree` for MacOs'
run: |
brew update
brew install tree
if: runner.os == 'macOS'
- name: "Install `tree` for Windows"
- name: 'Install `tree` for Windows'
run: |
choco install tree
if: runner.os == 'Windows'
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
test-workspace/
.vscode/
.vscode-test/
out/
dist/
webpack.config.js
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ either globally or per project. E.g.:

```json
{
"haskell.toolchain": {
"hls": "1.6.1.1",
"cabal": "recommended",
"stack": null
}
"haskell.toolchain": {
"hls": "1.6.1.1",
"cabal": "recommended",
"stack": null
}
}
```

Expand All @@ -131,11 +131,11 @@ Another config could be:

```json
{
"haskell.toolchain": {
"ghc": "9.2.2",
"hls": "latest"
"cabal": "recommended"
}
"haskell.toolchain": {
"ghc": "9.2.2",
"hls": "latest",
"cabal": "recommended"
}
}
```

Expand All @@ -151,11 +151,10 @@ The defaults (when omitted) are as follows:
1. install the project required `ghc` (corresponding to `with-compiler` setting in `cabal.project` for example)
2. install the latest `hls` version that supports the project required ghc version
3. install latest `cabal`
3. install latest `stack`
4. install latest `stack`

When a the value is `null`, the extension will refrain from installing it.


### Supported GHC versions

These are the versions of GHC that there are binaries of `haskell-language-server-1.6.1` for. Building from source may support more versions!
Expand Down Expand Up @@ -204,18 +203,16 @@ Please include the output when filing any issues on the [haskell-language-server

- Sometimes the language server might get stuck in a rut and stop responding to your latest changes.
Should this occur you can try restarting the language server with <kbd>Ctrl</kbd> <kbd>shift</kbd> <kbd>P</kbd>/<kbd>⌘</kbd> <kbd>shift</kbd> <kbd>P</kbd> > Restart Haskell LSP Server.

#### `Cradle requires ghc/cabal/stack but it isn't installed`

- In Linux/MacOS systems, opening vscode in the windows system could not use the `$PATH` set in the shell
so it will not see required tools as ghc, cabal or stack. This usually happens if you have installed them
via ghcup.
- It could be fixed changing the `$PATH` variable in the init config file used by the windows system
via ghcup.
- It could be fixed changing the `$PATH` variable in the init config file used by the windows system
(f.e. `~/.profile`, but i can vary depending on your system setup).
- See [this stackoverflow question](https://stackoverflow.com/questions/43983718/set-global-path-environment-variable-in-vs-code) for more tricks.



## Contributing

If you want to help, get started by reading [Contributing](https://github.com/haskell/vscode-haskell/blob/master/Contributing.md) for more details.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
"tslint-fix": "tslint --fix -p tsconfig.json -c tslint.json --format stylish 'src/**/*.ts'",
"push-tag": "git tag -a $npm_package_version -m \"Version $npm_package_version\" && git push origin $npm_package_version",
"pretest": "tsc -p ./",
"format": "prettier . --write",
"test": "node ./out/test/runTest.js"
},
"husky": {
Expand All @@ -447,7 +448,7 @@
"glob": "^7.1.4",
"husky": "^7.0.2",
"mocha": "^9.2.1",
"prettier": "^2.5.1",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.2",
"set-value": ">=4.0.1",
"ts-loader": "^9.2.8",
Expand Down
6 changes: 2 additions & 4 deletions src/commands/importIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as bent from 'bent';
import * as cheerio from 'cheerio';
import * as yaml from 'js-yaml';
import escapeRegExp from 'lodash-es/escapeRegExp';
import * as LRUCache from 'lru-cache';
import * as bent from 'bent';
import * as vscode from 'vscode';
import { CommandNames } from './constants';

const getJson = bent('json');

const askHoogle = async (variable: string): Promise<any> => {
return await getJson(
`https://hoogle.haskell.org/?hoogle=${variable}&scope=set%3Astackage&mode=json`
);
return await getJson(`https://hoogle.haskell.org/?hoogle=${variable}&scope=set%3Astackage&mode=json`);
};

const withCache =
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
* Deactivate each of the LSP servers.
*/
export async function deactivate() {
const promises: Array<Thenable<void>> = [];
const promises: Thenable<void>[] = [];
for (const client of clients.values()) {
if (client) {
promises.push(client.stop());
Expand Down
10 changes: 5 additions & 5 deletions src/hlsBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ export async function findHaskellLanguageServer(
await upgradeGHCup(context, logger);

// boring init
let latestHLS: string | undefined | null = undefined;
let latestCabal: string | undefined | null = undefined;
let latestStack: string | undefined | null = undefined;
let latestHLS: string | undefined | null;
let latestCabal: string | undefined | null;
let latestStack: string | undefined | null;
let recGHC: string | undefined | null = 'recommended';
let projectHls: string | undefined | null = undefined;
let projectGhc: string | undefined | null = undefined;
let projectHls: string | undefined | null;
let projectGhc: string | undefined | null;

// support explicit toolchain config
const toolchainConfig: ToolConfig = new Map(
Expand Down
6 changes: 4 additions & 2 deletions test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ function installExtension(vscodeExePath: string, extId: string) {

async function main() {
try {
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable'
, process.platform === 'win32' ? 'win32-x64-archive' : undefined);
const vscodeExecutablePath = await downloadAndUnzipVSCode(
'stable',
process.platform === 'win32' ? 'win32-x64-archive' : undefined
);

// We have to install this dependant extension
installExtension(vscodeExecutablePath, 'justusadam.language-haskell');
Expand Down
57 changes: 33 additions & 24 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ async function withTimeout(seconds: number, f: Promise<any>) {
return Promise.race([f, delay(seconds)]);
}

const wait = (ms: number) => new Promise(r => setTimeout(r, ms));

const retryOperation = (operation: () => Promise<any>, delay: number, retries: number) => new Promise((resolve, reject): Promise<any> => {
return operation()
.then(resolve)
.catch((reason) => {
if (retries > 0) {
return wait(delay)
.then(retryOperation.bind(null, operation, delay, retries - 1))
.then(resolve)
.catch(reject);
}
return reject(reason);
});
});

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));

const retryOperation = (operation: () => Promise<any>, delay: number, retries: number) =>
new Promise((resolve, reject): Promise<any> => {
return operation()
.then(resolve)
.catch((reason) => {
if (retries > 0) {
return wait(delay)
.then(retryOperation.bind(null, operation, delay, retries - 1))
.then(resolve)
.catch(reject);
}
return reject(reason);
});
});

function getHaskellConfig() {
return vscode.workspace.getConfiguration('haskell');
Expand Down Expand Up @@ -89,7 +89,8 @@ async function deleteFiles(dir: vscode.Uri, keepDirs: vscode.Uri[], pred?: (file
await deleteFiles(subDirectory, keepDirs, pred);

// remove directory if it is empty now
const isEmptyNow = await vscode.workspace.fs.readDirectory(subDirectory)
const isEmptyNow = await vscode.workspace.fs
.readDirectory(subDirectory)
.then((contents) => Promise.resolve(contents.length === 0));
if (isEmptyNow) {
console.log(`Deleting ${subDirectory}`);
Expand Down Expand Up @@ -125,11 +126,10 @@ suite('Extension Test Suite', () => {

suiteSetup(async () => {
const tmpdir = path.join(getWorkspaceRoot().uri.fsPath, 'tmp');
await deleteWorkspaceFiles(
[ joinUri(getWorkspaceRoot().uri, '.vscode')
, joinUri(getWorkspaceRoot().uri, 'bin', process.platform === 'win32' ? 'ghcup' : '.ghcup', 'cache')
]
);
await deleteWorkspaceFiles([
joinUri(getWorkspaceRoot().uri, '.vscode'),
joinUri(getWorkspaceRoot().uri, 'bin', process.platform === 'win32' ? 'ghcup' : '.ghcup', 'cache'),
]);
await getHaskellConfig().update('promptBeforeDownloads', false, vscode.ConfigurationTarget.Global);
await getHaskellConfig().update('manageHLS', 'GHCup');
await getHaskellConfig().update('logFile', 'hls.log');
Expand Down Expand Up @@ -185,8 +185,17 @@ suite('Extension Test Suite', () => {
await delay(20);
const logContents = getExtensionLogContent();
assert.ok(logContents, 'Extension log file does not exist');
assert.ok(retryOperation(() => new Promise((resolve, reject) => (logContents.match(/INFO hls:\s+Registering ide configuration/) !== null) ? resolve : reject), 1000 * 5, 20),
'Extension log file has no hls output');
assert.ok(
retryOperation(
() =>
new Promise((resolve, reject) =>
logContents.match(/INFO hls:\s+Registering ide configuration/) !== null ? resolve : reject
),
1000 * 5,
20
),
'Extension log file has no hls output'
);
});

test('Server should inherit environment variables defined in the settings', async () => {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1926,9 +1926,9 @@ prelude-ls@^1.2.1:
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier@^2.5.1:
prettier@^2.6.2:
version "2.6.2"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==

pretty-quick@^3.1.2:
Expand Down