Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
RodgeFu committed Dec 21, 2024
1 parent 87a3c92 commit b4bdba2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/typespec-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export async function activate(context: ExtensionContext) {
);

// Only try to start language server when some workspace has opened
// because the LSP client will popup error notification in vscode directly if failed to start (not our code, but in LanguageClient class...)
// which will be confusing to user if no workspace is opened (i.e. create TypeSpec project scenario)
// because the LanguageClient class will popup error notification in vscode directly if failing to start
// which will be confusing to user if no workspace is opened (i.e. in Create TypeSpec project scenario)
if ((vscode.workspace.workspaceFolders?.length ?? 0) > 0) {
await vscode.window.withProgress(
return await vscode.window.withProgress(
{
title: "Launching TypeSpec language service...",
location: vscode.ProgressLocation.Notification,
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-vscode/src/tsp-language-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class TspLanguageClient {
async start(): Promise<void> {
try {
if (this.client.needsStart()) {
// please be aware that this method may also popup error notification directly in vscode
// please be aware that this method would popup error notification in vscode directly
await this.client.start();
logger.info("TypeSpec server started");
} else {
Expand Down
4 changes: 0 additions & 4 deletions packages/typespec-vscode/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export interface InstallGlobalCliCommandArgs {
confirm: boolean;
confirmTitle?: string;
confirmPlaceholder?: string;
/**
* The command won't show output window or popup notification in silent mode
*/
silentMode?: boolean;
}

export interface RestartServerCommandArgs {
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-vscode/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ export function spawnExecution(
}

/**
* if the operation is cancelled, the promise will be rejected with @{link ResultCode.Cancelled}
* if the operation is timeout, the promise will be rejected with @{link ResultCode.Timeout}
* if the operation is cancelled, the promise will be rejected with {@link ResultCode.Cancelled}
* if the operation is timeout, the promise will be rejected with {@link ResultCode.Timeout}
*
* @param action
* @param token
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-vscode/src/vscode-cmd/create-tsp-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ async function checkProjectRootFolderEmpty(selectedFolder: string): Promise<bool
async function CheckCompilerAndStartLSPClient(folder: string): Promise<Result<TspLanguageClient>> {
// language server may not be started because no workspace is opened or failed to start for some reason
// so before trying to start it, let's try to check whether global compiler is available first
// to avoid unnecessary error notification when starting LSP which would be confusing.
// to avoid unnecessary error notification when starting LSP which would be confusing (we can't avoid it which
// is from base LanguageClient class...).
const r = await IsGlobalCompilerAvailable(folder);
if (r.code !== ResultCode.Success || r.value === undefined) {
return { code: r.code, details: r.details };
Expand All @@ -670,7 +671,6 @@ async function CheckCompilerAndStartLSPClient(folder: string): Promise<Result<Ts
confirmTitle: "No TypeSpec Compiler/CLI found which is needed to create TypeSpec project.",
confirmPlaceholder:
"No TypeSpec Compiler/CLI found which is needed to create TypeSpec project.",
silentMode: true,
};
const result = await vscode.commands.executeCommand<Result<void>>(
CommandName.InstallGlobalCompilerCli,
Expand Down
12 changes: 5 additions & 7 deletions packages/typespec-vscode/src/vscode-cmd/install-tsp-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const COMPILER_REQUIREMENT =
export async function installCompilerGlobally(
args: InstallGlobalCliCommandArgs | undefined,
): Promise<Result<void>> {
const showOutput = !(args?.silentMode ?? false);
const showPopup = !(args?.silentMode ?? false);
// confirm with end user by default
if (args?.confirm !== false) {
const yes: QuickPickItem = {
Expand Down Expand Up @@ -55,7 +53,7 @@ export async function installCompilerGlobally(
logger.error(
"Failed to install TypeSpec CLI. Please check the previous log for details",
[output],
{ showOutput, showPopup },
{ showOutput: true, showPopup: true },
);
return {
code: ResultCode.Fail,
Expand All @@ -71,14 +69,14 @@ export async function installCompilerGlobally(
return { code: ResultCode.Cancelled };
} else if (e === ResultCode.Timeout) {
logger.error(`Installation of TypeSpec Compiler/CLI is timeout after ${TIMEOUT}ms`, [e], {
showOutput,
showPopup,
showOutput: true,
showPopup: true,
});
return { code: ResultCode.Timeout };
} else {
logger.error("Unexpected error when installing TypeSpec Compiler/CLI", [e], {
showOutput,
showPopup,
showOutput: true,
showPopup: true,
});
return { code: ResultCode.Fail, details: e };
}
Expand Down

0 comments on commit b4bdba2

Please sign in to comment.