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

feat(plugin/ts): error handling when querying version matching #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions core/src/plugins/typescript/statusbar/Versions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,15 @@ export const Versions: React.ComponentType<BarItemProps<TypeScriptPluginX['ExtSh
</>))
}
if ('text' in result) {
// TODO resolve this case
console.log('text', result)
const matchVersion = suggestedVersions.filter(({ id }) => id.includes(result.text))
matchVersion.length > 0
? onChange?.(matchVersion[0]?.value.toString())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不可以直接强行切换到对应版本吗?🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以,但是如果他输入任何以外的值都给一个固定值,是不是不太符合直觉?

要不然在不匹配任何值的时候给一个固定@latest

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

预期的话应该是不管怎么样都设置过去,然后应该会触发 monaco 的加载,最后如果有版本那就会找到对应的版本并加载,如果找不到那么就会在下面编辑框的位置出现一些提示出来,我之前应该是做了这个异常逻辑的 fallback 的。

const loadingNode = useMemo(() => typescriptVersion ? null : <section style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column'
}}>
<div style={{
position: 'relative',
width: 72,
height: 72,
backgroundColor: '#4272ba',
userSelect: 'none'
}}>
<span style={{
position: 'absolute',
right: 5,
bottom: -2,
fontSize: 30,
fontWeight: 'blob'
}}>TS</span>
</div>
{loadError
? <span>{loadError}</span>
: <span>Downloading TypeScript{typescriptVersion && <>@<code>{typescriptVersion}</code></>} ...</span>}
</section>, [loadError, typescriptVersion])

可以检查一下能否强制切换到这个 fallback 逻辑。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 我看下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最终 loadingNode 会被加载到这个地方来

loading={loadingNode}

: messenger.then(m => m.display('error', <>
<h3>Invalid TypeScript Version</h3>
<p>Version <code>{matchVersion[0]?.id}</code> is not available.</p>
{/* TODO support help jump */}
<p>Click <a href='/TODO'>it</a> and find help.</p>
</>))
}
} catch (e) {
console.error(e)
Expand Down