Skip to content

Commit b799ead

Browse files
committed
Several corrections
1 parent 38bbf98 commit b799ead

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

package-lock.json

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ export async function activate(context: ExtensionContext) {
4747
const client = clients.get(folder.uri.toString());
4848
if (client) {
4949
const uri = folder.uri.toString();
50-
client.info('Deleting folder for clients: ${uri}');
50+
client.info(`Deleting folder for clients: ${uri}`);
5151
clients.delete(uri);
52-
client.info;
5352
client.info('Stopping the client');
5453
client.stop();
5554
}
@@ -103,26 +102,26 @@ function findManualExecutable(logger: Logger, uri: Uri, folder?: WorkspaceFolder
103102
if (exePath === '') {
104103
return null;
105104
}
106-
logger.info('Trying to find the server executable in: ${exePath}');
105+
logger.info(`Trying to find the server executable in: ${exePath}`);
107106
// Substitute path variables with their corresponding locations.
108107
exePath = exePath.replace('${HOME}', os.homedir).replace('${home}', os.homedir).replace(/^~/, os.homedir);
109108
if (folder) {
110109
exePath = exePath.replace('${workspaceFolder}', folder.uri.path).replace('${workspaceRoot}', folder.uri.path);
111110
}
112-
logger.info('Location after path variables subsitution: ${exePath}');
111+
logger.info(`Location after path variables subsitution: ${exePath}`);
113112
if (!executableExists(exePath)) {
114-
throw new Error(`serverExecutablePath is set to ${exePath} but it doesn't exist and is not on the PATH`);
113+
throw new Error(`serverExecutablePath is set to ${exePath} but it doesn't exist and it is not on the PATH`);
115114
}
116115
return exePath;
117116
}
118117

119118
/** Searches the PATH for whatever is set in serverVariant */
120119
function findLocalServer(context: ExtensionContext, logger: Logger, uri: Uri, folder?: WorkspaceFolder): string | null {
121120
const exes: string[] = ['haskell-language-server-wrapper', 'haskell-language-server'];
122-
logger.info('Searching for server executables ${exes} in PATH');
121+
logger.info(`Searching for server executables ${exes.join(' ')} in PATH`);
123122
for (const exe of exes) {
124123
if (executableExists(exe)) {
125-
logger.info('Found server executable in PATH: ${exe}');
124+
logger.info(`Found server executable in PATH: ${exe}`);
126125
return exe;
127126
}
128127
}
@@ -209,8 +208,8 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
209208
debug: { command: serverExecutable, transport: TransportKind.stdio, args, options: exeOptions },
210209
};
211210

212-
logger.info('run command: "' + serverExecutable + ' ' + args.join(' ') + '"');
213-
logger.info('debug command: "' + serverExecutable + ' ' + args.join(' ') + '"');
211+
logger.info(`run command: ${serverExecutable} ${args.join(' ')}`);
212+
logger.info(`debug command: ${serverExecutable} ${args.join(' ')}`);
214213
logger.info(`server cwd: ${exeOptions.cwd}`);
215214

216215
const pat = folder ? `${folder.uri.fsPath}/**/*` : '**/*';

src/hlsBinaries.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,27 @@ async function getProjectGhcVersion(
110110
return window.withProgress(
111111
{
112112
location: ProgressLocation.Notification,
113-
title: title,
113+
title: `${title}`,
114114
cancellable: true,
115115
},
116116
async (progress, token) => {
117117
return new Promise<string>((resolve, reject) => {
118118
const command: string = wrapper + ' --project-ghc-version';
119-
logger.info('Executing `${command}` in cwd ${dir} to get the project ghc version');
119+
logger.info(`Executing '${command}' in cwd ${dir} to get the project ghc version`);
120120
token.onCancellationRequested(() => {
121-
logger.warn('User canceled the executon of `${command}`');
121+
logger.warn(`User canceled the executon of '${command}'`);
122122
});
123123
// Need to set the encoding to 'utf8' in order to get back a string
124124
// We execute the command in a shell for windows, to allow use cmd or bat scripts
125-
let childProcess = child_process
125+
const childProcess = child_process
126126
.execFile(
127127
command,
128-
{ encoding: 'utf8', cwd: dir, shell: getGithubOS() == 'Windows' },
128+
{ encoding: 'utf8', cwd: dir, shell: getGithubOS() === 'Windows' },
129129
(err, stdout, stderr) => {
130130
if (err) {
131-
logger.error('Error executing `${command}` with error code ${err.code}');
132-
logger.error('stderr: ${stderr}');
133-
logger.error('stdout: ${stdout}');
131+
logger.error(`Error executing '${command}' with error code ${err.code}`);
132+
logger.error(`stderr: ${stderr}`);
133+
logger.error(`stdout: ${stdout}`);
134134
const regex = /Cradle requires (.+) but couldn't find it/;
135135
const res = regex.exec(stderr);
136136
if (res) {
@@ -144,10 +144,10 @@ async function getProjectGhcVersion(
144144
}
145145
)
146146
.on('close', (code, signal) => {
147-
logger.info('Execution of `${command}` closed with code ${err.code} and signal ${signal}');
147+
logger.info(`Execution of '${command}' closed with code ${code} and signal ${signal}`);
148148
})
149149
.on('error', (err) => {
150-
logger.error('Error execution `${command}`: name = ${err.name}, message = ${err.message}');
150+
logger.error(`Error executing '${command}': name = ${err.name}, message = ${err.message}`);
151151
throw err;
152152
});
153153
token.onCancellationRequested((_) => childProcess.kill());
@@ -305,8 +305,8 @@ export async function downloadHaskellLanguageServer(
305305
window.showErrorMessage(message);
306306
return null;
307307
}
308-
logger.info('The latest release is ${release.tag_name}');
309-
logger.info('Figure out the ghc version to use or advertise an installation link for missing components');
308+
logger.info(`The latest release is ${release.tag_name}`);
309+
logger.info(`Figure out the ghc version to use or advertise an installation link for missing components`);
310310
const dir: string = folder?.uri?.fsPath ?? path.dirname(resource.fsPath);
311311
let ghcVersion: string;
312312
try {
@@ -333,10 +333,12 @@ export async function downloadHaskellLanguageServer(
333333
// When searching for binaries, use startsWith because the compression may differ
334334
// between .zip and .gz
335335
const assetName = `haskell-language-server-${githubOS}-${ghcVersion}${exeExt}`;
336-
logger.info('Search for binary ${assetName} in release assests');
336+
logger.info(`Search for binary ${assetName} in release assests`);
337337
const asset = release?.assets.find((x) => x.name.startsWith(assetName));
338338
if (!asset) {
339-
logger.error('No binary ${assetName} found in the release assets: ' + release?.assets.map((value) => value.name));
339+
logger.error(
340+
`No binary ${assetName} found in the release assets: ${release?.assets.map((value) => value.name).join(',')}`
341+
);
340342
window.showInformationMessage(new NoBinariesError(release.tag_name, ghcVersion).message);
341343
return null;
342344
}
@@ -348,7 +350,7 @@ export async function downloadHaskellLanguageServer(
348350
logger.info(title);
349351
await downloadFile(title, asset.browser_download_url, binaryDest);
350352
if (ghcVersion.startsWith('9.')) {
351-
let warning =
353+
const warning =
352354
'Currently, HLS supports GHC 9 only partially. ' +
353355
'See [issue #297](https://github.com/haskell/haskell-language-server/issues/297) for more detail.';
354356
logger.warn(warning);

src/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,26 @@ export class ExtensionLogger implements Logger {
2828
this.level = this.getLogLevel(level);
2929
this.channel = channel;
3030
}
31-
warn(message: string): void {
31+
public warn(message: string): void {
3232
this.logLevel(LogLevel.Warn, message);
3333
}
34-
info(message: string): void {
34+
35+
public info(message: string): void {
3536
this.logLevel(LogLevel.Info, message);
3637
}
3738

38-
error(message: string) {
39+
public error(message: string) {
3940
this.logLevel(LogLevel.Error, message);
4041
}
4142

42-
log(msg: string) {
43+
public log(msg: string) {
4344
this.channel.appendLine(msg);
4445
}
4546

4647
private logLevel(level: LogLevel, msg: string) {
47-
if (level <= this.level) this.log('[${name}][${level}] ${msg}');
48+
if (level <= this.level) {
49+
this.log(`[${this.name}][${level}] ${msg}`);
50+
}
4851
}
4952

5053
private getLogLevel(level: string) {

0 commit comments

Comments
 (0)