Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/code-language-typescript",
"comment": "remote ts dependency",
"type": "patch"
}
],
"packageName": "@coze-editor/code-language-typescript",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/code-language-typescript",
"comment": "remove ts dependencies",
"type": "minor"
}
],
"packageName": "@coze-editor/code-language-typescript",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/code-language-typescript",
"comment": "ts license",
"type": "minor"
}
],
"packageName": "@coze-editor/code-language-typescript",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/preset-code",
"comment": "preset code",
"type": "minor"
}
],
"packageName": "@coze-editor/preset-code",
"email": "[email protected]"
}
37 changes: 37 additions & 0 deletions common/config/subspaces/default/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/text-editor/code-language-typescript/src/as.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: MIT

import { CompletionItemKind } from 'vscode-languageserver-types';
import { ScriptElementKind } from 'typescript';

import { ScriptElementKind } from './ts-enums';

/*
* Copyright (C) 2018 TypeFox and others.
Expand Down
5 changes: 2 additions & 3 deletions packages/text-editor/code-language-typescript/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
} from 'vscode-languageserver-types';
import {
type CompletionEntryDetails,
DiagnosticCategory,
displayPartsToString,
type FormatCodeSettings,
} from 'typescript';
import mitt from 'mitt';
Expand All @@ -29,8 +27,9 @@ import type {
TransactionSpec,
} from '@codemirror/state';

import { tagToString } from './utils';
import { displayPartsToString, tagToString } from './utils';
import type { InitializeOptions, ITypeScriptWorker } from './types';
import { DiagnosticCategory } from './ts-enums';
import { asCompletionItemKind } from './as';

function isDiagnostic(v: unknown): v is Diagnostic {
Expand Down
107 changes: 107 additions & 0 deletions packages/text-editor/code-language-typescript/src/ts-enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

export enum ScriptElementKind {
unknown = '',
warning = 'warning',
/** predefined type (void) or keyword (class) */
keyword = 'keyword',
/** top level script node */
scriptElement = 'script',
/** module foo {} */
moduleElement = 'module',
/** class X {} */
classElement = 'class',
/** var x = class X {} */
localClassElement = 'local class',
/** interface Y {} */
interfaceElement = 'interface',
/** type T = ... */
typeElement = 'type',
/** enum E */
enumElement = 'enum',
enumMemberElement = 'enum member',
/**
* Inside module and script only
* const v = ..
*/
variableElement = 'var',
/** Inside function */
localVariableElement = 'local var',
/** using foo = ... */
variableUsingElement = 'using',
/** await using foo = ... */
variableAwaitUsingElement = 'await using',
/**
* Inside module and script only
* function f() { }
*/
functionElement = 'function',
/** Inside function */
localFunctionElement = 'local function',
/** class X { [public|private]* foo() {} } */
memberFunctionElement = 'method',
/** class X { [public|private]* [get|set] foo:number; } */
memberGetAccessorElement = 'getter',
memberSetAccessorElement = 'setter',
/**
* class X { [public|private]* foo:number; }
* interface Y { foo:number; }
*/
memberVariableElement = 'property',
/** class X { [public|private]* accessor foo: number; } */
memberAccessorVariableElement = 'accessor',
/**
* class X { constructor() { } }
* class X { static { } }
*/
constructorImplementationElement = 'constructor',
/** interface Y { ():number; } */
callSignatureElement = 'call',
/** interface Y { []:number; } */
indexSignatureElement = 'index',
/** interface Y { new():Y; } */
constructSignatureElement = 'construct',
/** function foo(*Y*: string) */
parameterElement = 'parameter',
typeParameterElement = 'type parameter',
primitiveType = 'primitive type',
label = 'label',
alias = 'alias',
constElement = 'const',
letElement = 'let',
directory = 'directory',
externalModuleName = 'external module name',
/**
* <JsxTagName attribute1 attribute2={0} />
* @deprecated
*/
jsxAttribute = 'JSX attribute',
/** String literal */
string = 'string',
/** Jsdoc @link: in `{@link C link text}`, the before and after text "{@link " and "}" */
link = 'link',
/** Jsdoc @link: in `{@link C link text}`, the entity name "C" */
linkName = 'link name',
/** Jsdoc @link: in `{@link C link text}`, the link text "link text" */
linkText = 'link text',
}

export enum DiagnosticCategory {
Warning = 0,
Error = 1,
Suggestion = 2,
Message = 3,
}
10 changes: 9 additions & 1 deletion packages/text-editor/code-language-typescript/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT

import type ts from 'typescript';
import { type SymbolDisplayPart } from 'typescript';

function tagToString(tag: ts.JSDocTagInfo): string {
let tagLabel = `*@${tag.name}*`;
Expand All @@ -19,4 +20,11 @@ function tagToString(tag: ts.JSDocTagInfo): string {
return tagLabel;
}

export { tagToString };
function displayPartsToString(displayParts?: SymbolDisplayPart[]) {
if (displayParts) {
return displayParts.map(displayPart2 => displayPart2.text).join('');
}
return '';
}

export { tagToString, displayPartsToString };
3 changes: 2 additions & 1 deletion packages/text-editor/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"tailwindcss": "~3.3.3",
"typescript": "^5.8.2",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
"vite": "^6.3.5",
"vite-bundle-analyzer": "~1.2.1"
}
}
6 changes: 2 additions & 4 deletions packages/text-editor/dev/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createRoot } from 'react-dom/client';
import Page from './pages/prompt';
import Page from './pages/code';
import './index.css';

createRoot(document.getElementById('app')!).render(
<Page />
)
createRoot(document.getElementById('app')!).render(<Page />);
13 changes: 7 additions & 6 deletions packages/text-editor/dev/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'node:path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { analyzer } from 'vite-bundle-analyzer';

// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), analyzer()],
server: {
fs: {
strict: false,
}
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
})
});
2 changes: 2 additions & 0 deletions packages/text-editor/preset-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"@coze-editor/vscode": "workspace:*",
"@lezer/highlight": "~1.2.0",
"@nozbe/microfuzz": "^1.0.0",
"@shikijs/langs": "~3.12.0",
"@shikijs/themes": "~3.12.0",
"codemirror-shiki": "^0.2.2",
"marked": "^15.0.7",
"marked-shiki": "^1.2.0",
Expand Down
23 changes: 19 additions & 4 deletions packages/text-editor/preset-code/src/highlighter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
// Copyright (c) 2025 coze-dev
// SPDX-License-Identifier: MIT

import { createHighlighter } from 'shiki';
import { createOnigurumaEngine } from 'shiki/engine/oniguruma';
import { createHighlighterCore } from 'shiki/core';

const highlighterPromise = createHighlighter({
langs: ['md', 'js', 'ts', 'python'],
themes: ['github-dark', 'one-dark-pro'],
// const highlighterPromise = createHighlighter({
// langs: ['md', 'js', 'ts', 'python'],
// themes: ['github-dark', 'one-dark-pro'],
// });

const highlighterPromise = createHighlighterCore({
langs: [
() => import('@shikijs/langs/markdown'),
() => import('@shikijs/langs/javascript'),
() => import('@shikijs/langs/typescript'),
() => import('@shikijs/langs/python'),
],
themes: [
() => import('@shikijs/themes/github-dark'),
() => import('@shikijs/themes/one-dark-pro'),
],
engine: createOnigurumaEngine(import('shiki/wasm')),
});

export { highlighterPromise };