Skip to content

Commit ed8409b

Browse files
committed
More typechecking and fix the type errors
1 parent 3685f9e commit ed8409b

File tree

6 files changed

+98
-122
lines changed

6 files changed

+98
-122
lines changed

eslint.config.mjs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
import globals from 'globals';
2-
import pluginJs from '@eslint/js';
2+
import eslint from '@eslint/js';
33
import tseslint from 'typescript-eslint';
44

5-
export default [
5+
export default tseslint.config(
66
{ files: ['**/*.{js,mjs,cjs,ts}'] },
7-
{ languageOptions: { globals: globals.node } },
87
{
9-
...pluginJs.configs.recommended,
10-
...tseslint.configs.recommendedTypeChecked,
8+
languageOptions: {
9+
globals: globals.node,
10+
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
11+
},
12+
},
13+
{
14+
// disables type checking for this file only
15+
files: ['eslint.config.mjs'],
16+
extends: [tseslint.configs.disableTypeChecked],
17+
},
18+
eslint.configs.recommended,
19+
tseslint.configs.recommendedTypeChecked,
20+
{
1121
rules: {
22+
// turn off these lints as we access workspaceConfiguration fields.
23+
// So far, there was no bug found with these unsafe accesses.
24+
'@typescript-eslint/no-unsafe-assignment': 'off',
25+
'@typescript-eslint/no-unsafe-member-access': 'off',
26+
// Sometimes, the 'any' just saves too much time.
1227
'@typescript-eslint/no-explicit-any': 'off',
28+
'@typescript-eslint/no-floating-promises': 'error',
1329
'@typescript-eslint/no-unused-vars': [
1430
'error',
1531
{
@@ -24,5 +40,4 @@ export default [
2440
],
2541
},
2642
},
27-
...tseslint.configs.recommended,
28-
];
43+
);

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OutputChannel, Uri, window, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
22
import { expandHomeDir, ExtensionLogger, IEnvVars } from './utils';
3-
import path = require('path');
3+
import * as path from 'path';
44
import { Logger } from 'vscode-languageclient';
55

66
export type LogLevel = 'off' | 'messages' | 'verbose';

src/docsBrowser.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { dirname } from 'path';
32
import {
43
CancellationToken,
@@ -51,7 +50,7 @@ async function showDocumentation({
5150
const bytes = await workspace.fs.readFile(Uri.parse(localPath));
5251

5352
const addBase = `
54-
<base href="${panel.webview.asWebviewUri(Uri.parse(documentationDirectory))}/">
53+
<base href="${panel.webview.asWebviewUri(Uri.parse(documentationDirectory)).toString()}/">
5554
`;
5655

5756
panel.webview.html = `
@@ -63,8 +62,10 @@ async function showDocumentation({
6362
</body>
6463
</html>
6564
`;
66-
} catch (e: any) {
67-
await window.showErrorMessage(e);
65+
} catch (e) {
66+
if (e instanceof Error) {
67+
await window.showErrorMessage(e.message);
68+
}
6869
}
6970
return panel;
7071
}
@@ -87,8 +88,10 @@ async function openDocumentationOnHackage({
8788
if (inWebView) {
8889
await commands.executeCommand('workbench.action.closeActiveEditor');
8990
}
90-
} catch (e: any) {
91-
await window.showErrorMessage(e);
91+
} catch (e) {
92+
if (e instanceof Error) {
93+
await window.showErrorMessage(e.message);
94+
}
9295
}
9396
}
9497

@@ -154,11 +157,9 @@ function processLink(ms: MarkdownString | MarkedString): string | MarkdownString
154157
cmd = 'command:haskell.showDocumentation?' + encoded;
155158
}
156159
return `[${title}](${cmd})`;
157-
} else if (title === 'Source') {
158-
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/src/${fileAndAnchor.replace(
159-
/-/gi,
160-
'.',
161-
)}`;
160+
} else if (title === 'Source' && typeof fileAndAnchor === 'string') {
161+
const moduleLocation = fileAndAnchor.replace(/-/gi, '.');
162+
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/src/${moduleLocation}`;
162163
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
163164
let cmd: string;
164165
if (openSourceInHackage) {
@@ -174,7 +175,7 @@ function processLink(ms: MarkdownString | MarkedString): string | MarkdownString
174175
);
175176
}
176177
if (typeof ms === 'string') {
177-
return transform(ms as string);
178+
return transform(ms);
178179
} else if (ms instanceof MarkdownString) {
179180
const mstr = new MarkdownString(transform(ms.value));
180181
mstr.isTrusted = true;

src/extension.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ export async function activate(context: ExtensionContext) {
2626
// just support
2727
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#workspace_workspaceFolders
2828
// and then we can just launch one server
29-
workspace.onDidOpenTextDocument(async (document: TextDocument) => await activeServer(context, document));
30-
workspace.textDocuments.forEach(async (document: TextDocument) => await activeServer(context, document));
29+
workspace.onDidOpenTextDocument(async (document: TextDocument) => await activateServer(context, document));
30+
for (const document of workspace.textDocuments) {
31+
await activateServer(context, document);
32+
}
3133

3234
// Stop the server from any workspace folders that are removed.
33-
workspace.onDidChangeWorkspaceFolders((event) => {
35+
workspace.onDidChangeWorkspaceFolders(async (event) => {
3436
for (const folder of event.removed) {
3537
const client = clients.get(folder.uri.toString());
3638
if (client) {
3739
const uri = folder.uri.toString();
3840
client.info(`Deleting folder for clients: ${uri}`);
3941
clients.delete(uri);
4042
client.info('Stopping the server');
41-
client.stop();
43+
await client.stop();
4244
}
4345
}
4446
});
@@ -49,7 +51,7 @@ export async function activate(context: ExtensionContext) {
4951
langClient?.info('Stopping the server');
5052
await langClient?.stop();
5153
langClient?.info('Starting the server');
52-
langClient?.start();
54+
await langClient?.start();
5355
}
5456
});
5557

@@ -68,7 +70,7 @@ export async function activate(context: ExtensionContext) {
6870
const startCmd = commands.registerCommand(StartServerCommandName, async () => {
6971
for (const langClient of clients.values()) {
7072
langClient?.info('Starting the server');
71-
langClient?.start();
73+
await langClient?.start();
7274
langClient?.info('Server started');
7375
}
7476
});
@@ -83,7 +85,7 @@ export async function activate(context: ExtensionContext) {
8385
context.subscriptions.push(openOnHackageDisposable);
8486
}
8587

86-
async function activeServer(context: ExtensionContext, document: TextDocument) {
88+
async function activateServer(context: ExtensionContext, document: TextDocument) {
8789
// We are only interested in Haskell files.
8890
if (
8991
(document.languageId !== 'haskell' &&
@@ -97,7 +99,7 @@ async function activeServer(context: ExtensionContext, document: TextDocument) {
9799
const uri = document.uri;
98100
const folder = workspace.getWorkspaceFolder(uri);
99101

100-
activateServerForFolder(context, uri, folder);
102+
await activateServerForFolder(context, uri, folder);
101103
}
102104

103105
async function activateServerForFolder(context: ExtensionContext, uri: Uri, folder?: WorkspaceFolder) {

0 commit comments

Comments
 (0)