Skip to content

Commit

Permalink
fix: fix windows endline bug and code viewer helper file ext incorrec…
Browse files Browse the repository at this point in the history
…t bug
  • Loading branch information
2214962083 committed Aug 8, 2024
1 parent 97ef4be commit 43a8049
Show file tree
Hide file tree
Showing 38 changed files with 1,224 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"titleBar.activeForeground": "#F8FCFD"
},
"cSpell.words": [
"allowtransparency",
"autoplay",
"bilibili",
"Codegee",
"Codeium",
"commitlint",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"command.replaceFile": "Replace original",
"command.showDiff": "Compare original",
"config.title": "Aide Configuration",
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/getting-started/how-to-configure-openai-key) or [I Don't Have an OpenAI Key](https://aide.nicepkg.cn/guide/getting-started/how-to-configure-openai-key#i-don-t-have-an-openai-key)",
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"command.replaceFile": "Replace original",
"command.showDiff": "Compare original",
"config.title": "Aide Configuration",
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/getting-started/how-to-configure-openai-key) or [I Don't Have an OpenAI Key](https://aide.nicepkg.cn/guide/getting-started/how-to-configure-openai-key#i-don-t-have-an-openai-key)",
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"command.replaceFile": "替换原文",
"command.showDiff": "对比原文",
"config.title": "Aide 配置",
"config.openaiKey.description": "OpenAI Key, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-key)",
"config.openaiKey.description": "OpenAI Key, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/getting-started/how-to-configure-openai-key) 或者 [我没有 OpenAI Key](https://aide.nicepkg.cn/zh/guide/getting-started/how-to-configure-openai-key#%E6%88%91%E6%B2%A1%E6%9C%89-openai-key)",
"config.openaiModel.description": "OpenAI Model, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API 请求并发数, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/api-concurrency)",
Expand Down
11 changes: 8 additions & 3 deletions src/commands/code-convert/get-target-language-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getConfigKey, setConfigKey } from '@/config'
import { languageIdExts, languageIds } from '@/constants'
import { t } from '@/i18n'
import { getLanguageId, showQuickPickWithCustomInput } from '@/utils'
import {
getLanguageId,
getLanguageIdExt,
showQuickPickWithCustomInput
} from '@/utils'
import * as vscode from 'vscode'

/**
Expand Down Expand Up @@ -43,13 +47,14 @@ export const getTargetLanguageInfo = async (originalFileLanguageId: string) => {
}
}

const [targetLanguageIdOrExt, ...targetLanguageRest] =
const [targetLanguageIdOrExt = 'plaintext', ...targetLanguageRest] =
targetLanguageInfo.split(/\s+/)
const targetLanguageDescription = targetLanguageRest.join(' ')
const targetLanguageId = getLanguageId(targetLanguageIdOrExt || 'plaintext')
const targetLanguageId = getLanguageId(targetLanguageIdOrExt)

return {
targetLanguageId: targetLanguageId || targetLanguageInfo,
targetLanguageExt: getLanguageIdExt(targetLanguageIdOrExt),
targetLanguageDescription: targetLanguageDescription?.trim() || ''
}
}
3 changes: 2 additions & 1 deletion src/commands/code-convert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const handleCodeConvert = async () => {
isTmpFileHasContent
} = await createTmpFileInfo()

const { targetLanguageId, targetLanguageDescription } =
const { targetLanguageId, targetLanguageExt, targetLanguageDescription } =
await getTargetLanguageInfo(originalFileLanguageId)

// ai
Expand Down Expand Up @@ -65,6 +65,7 @@ export const handleCodeConvert = async () => {

const tmpFileWriterReturns = await tmpFileWriter({
languageId: targetLanguageId,
ext: targetLanguageExt,
onCancel() {
aiRunnableAbortController.abort()
},
Expand Down
2 changes: 2 additions & 0 deletions src/commands/code-viewer-helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const cleanupCodeViewerHelperRunnables = async () => {

export const handleCodeViewerHelper = async () => {
const {
originalFileExt,
originalFileContent,
originalFileLanguageId,
tmpFileUri,
Expand Down Expand Up @@ -56,6 +57,7 @@ export const handleCodeViewerHelper = async () => {
})

const tmpFileWriterReturns = await tmpFileWriter({
ext: originalFileExt,
languageId: originalFileLanguageId,
onCancel() {
aiRunnableAbortController.abort()
Expand Down
22 changes: 16 additions & 6 deletions src/file-utils/create-tmp-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export const getTmpFileUri = ({
originalFileUri,
originalFileFullPath,
languageId,
ext,
untitled = true
}: {
originalFileUri?: vscode.Uri
originalFileFullPath?: string
languageId: string
ext?: string
untitled?: boolean
}) => {
if (!originalFileUri && !originalFileFullPath)
Expand All @@ -29,7 +31,7 @@ export const getTmpFileUri = ({
const originalFileDir = path.dirname(filePath)
const originalFileName = path.parse(filePath).name
const originalFileExt = path.parse(filePath).ext
const languageExt = getLanguageIdExt(languageId) || languageId
const languageExt = ext || getLanguageIdExt(languageId) || languageId

const finalPath = path.join(
originalFileDir,
Expand Down Expand Up @@ -118,6 +120,11 @@ export interface TmpFileInfo {
*/
originalFileLanguageId: string

/**
* The extension of the original file.
*/
originalFileExt: string

/**
* Indicates whether the active file is the original file.
*/
Expand Down Expand Up @@ -175,6 +182,7 @@ export const createTmpFileInfo = async (): Promise<TmpFileInfo> => {
}

const originalFileLanguageId = originalFileDocument.languageId
const originalFileExt = path.extname(originalFileUri.fsPath).slice(1)
const tmpFileUri = getTmpFileUri({
originalFileUri,
languageId: originalFileLanguageId
Expand All @@ -190,6 +198,7 @@ export const createTmpFileInfo = async (): Promise<TmpFileInfo> => {
originalFileDocument,
originalFileContent,
originalFileLanguageId,
originalFileExt,
activeIsOriginalFile,
isSelection,
tmpFileUri,
Expand All @@ -199,6 +208,7 @@ export const createTmpFileInfo = async (): Promise<TmpFileInfo> => {
}

export interface CreateTmpFileOptions {
ext?: string
languageId?: string
tmpFileUri?: vscode.Uri
}
Expand Down Expand Up @@ -280,7 +290,11 @@ export const createTmpFileAndWriter = async (

const tmpFileUri =
options.tmpFileUri ||
getTmpFileUri({ originalFileUri, languageId: languageId! })
getTmpFileUri({
originalFileUri,
languageId: languageId!,
ext: options.ext
})

const tmpDocument = await vscode.workspace.openTextDocument(tmpFileUri)
const isDocumentAlreadyShown = vscode.window.visibleTextEditors.some(
Expand All @@ -295,10 +309,6 @@ export const createTmpFileAndWriter = async (
}

if (languageId) {
// const docLanguageId = languageIds.includes(languageId)
// ? languageId
// : 'plaintext'

vscode.languages.setTextDocumentLanguage(tmpDocument, languageId)
}

Expand Down
22 changes: 18 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ export const commandErrorCatcher = <T extends (...args: any[]) => any>(
}
}) as T

export const getLanguageIdExt = (languageId: string): string =>
languageIdExtMap[languageId as keyof typeof languageIdExtMap]?.[0] || ''
export const getLanguageIdExt = (languageIdORExt: string): string => {
if (languageIdExts.includes(languageIdORExt)) return languageIdORExt

return (
languageIdExtMap[languageIdORExt as keyof typeof languageIdExtMap]?.[0] ||
''
)
}

export const getLanguageId = (languageIdORExt: string): string => {
if (languageIds.includes(languageIdORExt)) return languageIdORExt
Expand Down Expand Up @@ -153,8 +159,16 @@ export const sleep = (ms: number): Promise<void> =>

export const normalizeLineEndings = (text?: string): string => {
if (!text) return ''
if (process.platform !== 'win32') return text
return text.replace(/\n/g, '\r\n')

const activeEditor = vscode.window.activeTextEditor
if (!activeEditor) return text

const { eol } = activeEditor.document

if (eol === vscode.EndOfLine.LF) return text.replace(/\r\n/g, '\n')
if (eol === vscode.EndOfLine.CRLF) return text.replace(/\n/g, '\r\n')

return text
}

type QuickPickItemType = string | vscode.QuickPickItem
Expand Down
4 changes: 4 additions & 0 deletions website/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function sidebar(): DefaultTheme.Sidebar {
items: [
{ text: 'Introduction', link: '/' },
{ text: 'Installation', link: '/installation' },
{
text: 'How to Configure OpenAI Key',
link: '/how-to-configure-openai-key'
},
{
text: 'Customize Shortcuts',
link: '/customize-shortcuts'
Expand Down
19 changes: 18 additions & 1 deletion website/.vitepress/config/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Mark from 'markdown-it-mark'
import Unocss from 'unocss/vite'
import { defineConfig } from 'vitepress'

import { bilibiliSvg } from './svg'
import { search as zhSearch } from './zh'

export const shared = defineConfig({
Expand Down Expand Up @@ -58,7 +59,23 @@ export const shared = defineConfig({
themeConfig: {
logo: { src: '/logo-mini.svg', width: 24, height: 24 },

socialLinks: [{ icon: 'github', link: 'https://github.com/nicepkg/aide' }],
socialLinks: [
{ icon: 'github', link: 'https://github.com/nicepkg/aide' },
{
icon: 'twitter',
link: 'https://x.com/jinmingyang666'
},
{
icon: 'youtube',
link: 'https://www.youtube.com/@jinmingyang666'
},
{
icon: {
svg: bilibiliSvg
},
link: 'https://space.bilibili.com/83540912'
}
],

// search: {
// provider: 'algolia',
Expand Down
1 change: 1 addition & 0 deletions website/.vitepress/config/svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const bilibiliSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="20px" height="20px" viewBox="0 0 1024 1024"><path fill="currentColor" fill-rule="evenodd" d="M235.516 616.574c16.736-.741 32.287-1.778 47.69-2.074c66.797-1.185 132.409 6.814 194.762 31.998c30.51 12.296 59.984 26.517 86.495 46.516c21.772 16.444 26.512 36.887 16.588 67.108c-6.22 18.665-18.661 32.739-34.36 45.034c-37.028 28.888-75.832 54.96-120.412 69.626c-31.251 10.37-63.687 18.222-96.27 23.259c-42.803 6.666-86.2 9.629-129.447 13.628c-8.886.89-17.92-.296-26.807-.296c-4.591 0-5.776-2.37-5.924-6.37c-1.185-19.703-2.074-39.553-3.851-59.256c-2.222-25.48-4.74-50.96-7.702-76.292c-3.999-35.406-8.442-70.663-12.885-105.92c-4.592-37.184-9.331-74.22-13.774-111.403c-4.443-36.294-8.442-72.736-13.182-109.03c-5.332-41.48-11.256-82.96-16.884-124.439c-6.665-49.033-15.848-97.623-28.437-145.473c-.592-2.074 1.185-6.666 2.962-7.259c41.915-16.889 83.978-33.331 125.892-50.071c13.922-5.63 15.107-7.26 15.255 10.37c.148 75.107.444 150.214 1.63 225.321c.592 39.11 2.073 78.218 4.739 117.18c3.258 47.552 8.294 95.106 12.589 142.659c0 2.074.889 4 1.333 5.185m83.68 218.062a74372 74372 0 0 0 114.784-86.958c-4.74-6.815-109.303-47.85-133.89-53.33c6.221 46.367 12.59 92.587 19.107 140.288m434.12-14.387C733.38 618.113 716.544 413.756 678 210.584c12.553-1.481 25.106-3.258 37.806-4.295c14.62-1.332 29.388-1.925 44.009-3.11c12.257-1.036 16.835 2.222 17.574 14.217c2.215 32.134 4.135 64.268 6.35 96.403c2.953 43.388 6.055 86.925 9.156 130.314c2.215 31.246 4.135 62.64 6.646 93.886c2.805 34.207 5.907 68.267 9.008 102.474c2.215 25.175 4.283 50.497 6.793 75.672c2.658 27.247 5.612 54.495 8.418 81.742c.738 7.849 1.624 15.697 2.215 23.546c.296 4.294-2.067 4.887-6.055 4.442c-21.709-2.221-43.418-3.85-66.603-5.627M572 527.155c17.616-2.517 34.639-5.33 51.662-7.254c12.287-1.48 24.721-1.629 37.008-2.813c6.661-.593 10.954 1.776 11.99 8.29c2.813 17.322 5.773 34.79 7.846 52.26c3.405 29.017 6.07 58.182 9.178 87.199c2.664 25.464 5.329 50.78 8.29 76.243c3.256 27.24 6.809 54.333 10.213 81.425c1.037 7.995 1.777 16.137 2.813 24.872A9507 9507 0 0 0 636.245 857C614.929 747.15 593.612 638.189 572 527.155m382 338.821c-24.084 0-47.276.148-70.468-.296c-1.933 0-5.352-3.409-5.501-5.484c-3.568-37.05-6.69-73.953-9.96-111.004l-9.367-103.149c-3.27-35.42-6.393-70.841-9.663-106.262c-.149-2.074-.595-4.001-1.041-7.113c8.623-1.038 16.8-2.668 25.125-2.668c22.449 0 44.897.593 67.495 1.186c5.798.148 8.325 4.001 8.623 9.336c.743 11.116 1.784 22.083 1.784 33.198c.148 52.167-.149 104.483.297 156.65c.446 41.646 1.784 83.439 2.676 125.084zM622.069 480c-5.307-42.568-10.614-84.102-16.069-127.409c13.857-.148 27.715-.591 41.425-.591c4.57 0 6.634 2.513 7.076 7.538c3.686 38.725 7.519 77.45 11.499 117.654c-14.3.739-29.042 1.773-43.931 2.808M901 364.066c11.937 0 24.619-.148 37.45 0c6.417.148 9.55 2.672 9.55 10.244c-.448 36.224-.15 72.449-.15 108.525V491c-15.367-.742-30.139-1.485-46.7-2.227c-.15-41.124-.15-82.396-.15-124.707M568.569 489c-7.424-41.193-14.996-82.091-22.569-124.023c13.512-2.067 27.023-4.282 40.387-5.906c5.939-.738 4.9 4.43 5.197 7.678c1.633 13.879 2.82 27.61 4.305 41.488c2.376 21.704 4.752 43.408 6.979 64.965c.297 2.805 0 5.758 0 8.859c-11.284 2.362-22.569 4.577-34.299 6.939M839 365.16c12.718 0 25.435.148 38.004-.148c5.685-.149 7.78 1.038 7.63 7.563c-.449 17.352.15 34.704.3 52.204c.15 21.505 0 43.157 0 64.513c-12.868 1.335-24.09 2.373-36.209 3.708c-3.142-41.97-6.433-83.793-9.725-127.84"/></svg>`
8 changes: 7 additions & 1 deletion website/.vitepress/config/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ function sidebar(): DefaultTheme.Sidebar {
text: '安装',
link: '/installation'
},
{
text: '如何配置 OpenAI Key',
link: '/how-to-configure-openai-key'
},
{
text: '自定义快捷键',
link: '/customize-shortcuts'
Expand All @@ -92,7 +96,8 @@ function sidebar(): DefaultTheme.Sidebar {
text: '自定义配置',
link: '/customize-configuration'
},
{ text: '常见问题解答', link: '/faq' }
{ text: '常见问题解答', link: '/faq' },
{ text: '社区', link: '/community' }
]
},
{
Expand Down Expand Up @@ -199,6 +204,7 @@ function sidebar(): DefaultTheme.Sidebar {
collapsed: true,
base: '/zh/guide/use-another-llm',
items: [
{ text: 'Aide 模型聚合(便宜)', link: '/aide-models' },
{ text: 'Anthropic', link: '/anthropic' },
{ text: 'Azure', link: '/azure' },
{ text: 'DeepSeek', link: '/deepseek' },
Expand Down
4 changes: 4 additions & 0 deletions website/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { App } from 'vue'

import '@nolebase/vitepress-plugin-inline-link-preview/client/style.css'

import AideModelPrice from '../../components/AideModels/AideModelPrice.vue'
import AidePay from '../../components/AideModels/AidePay.vue'
import Video from '../../components/Video.vue'

import 'virtual:uno.css'
Expand All @@ -13,6 +15,8 @@ export default {
extends: DefaultTheme,
enhanceApp({ app }: { app: App }) {
app.component('Video', Video)
app.component('AidePay', AidePay)
app.component('AideModelPrice', AideModelPrice)
app.use(NolebaseInlineLinkPreviewPlugin)
}
}
Loading

0 comments on commit 43a8049

Please sign in to comment.