-
Notifications
You must be signed in to change notification settings - Fork 387
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: support terminal intelligence #3390
Open
life2015
wants to merge
16
commits into
main
Choose a base branch
from
feat/terminal-intell-alpha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
064e050
feat: terminal intell new
life2015 dd4e0a1
fix: compile error fix
life2015 99ad0be
feat: optimize and redesign terminal complete ui
life2015 0a39956
feat: refactor terminal intell runtime, support both browser and node
life2015 1e3a35e
feat: support cwd change
life2015 dd50f0d
feat: support terminal intell complete settings
life2015 73ac689
feat: adjust style
life2015 9115d6d
chore: lint fix
life2015 2232750
feat: support fig insertValue
life2015 066eee5
chore: fix lint
life2015 9d5f094
feat: terminal intell settings i18n
life2015 9fecbb2
Merge branch 'main' into feat/terminal-intell-alpha
life2015 3f7f5a2
chore: remove obsolete bundle.js
life2015 3ca4696
chore: more copyright info, use runWhenIdle
life2015 ee98762
Merge branch 'main' into feat/terminal-intell-alpha
life2015 5be010d
Merge branch 'main' into feat/terminal-intell-alpha
life2015 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/terminal-next/src/browser/component/terminal-intell-command-controller.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.suggestions { | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--editorGroupHeader-tabsBackground); | ||
color: var(--ai-native-text-color-common); | ||
max-height: 350px; | ||
width: 500px; | ||
overflow-y: auto; | ||
position: absolute; | ||
bottom: 100%; | ||
left: 0; | ||
border-top-left-radius: 8px; | ||
border-top-right-radius: 8px; | ||
} | ||
|
||
.suggestionItem { | ||
padding: 6px 10px 6px 16px; | ||
cursor: pointer; | ||
} | ||
|
||
.suggestionItemContainer { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.suggestionDesc { | ||
font-size: 12px; | ||
} | ||
|
||
.suggestionCmd { | ||
font-size: 12px; | ||
opacity: 0.6; | ||
} | ||
|
||
.suggestionItem:hover { | ||
filter: brightness(110%); | ||
background-color: var(--selection-background); | ||
} |
119 changes: 119 additions & 0 deletions
119
packages/terminal-next/src/browser/component/terminal-intell-command-controller.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { Emitter } from '@opensumi/ide-core-common'; | ||
|
||
import styles from './terminal-intell-command-controller.module.less'; | ||
|
||
export interface SmartCommandDesc { | ||
description: string; | ||
command: string; | ||
} | ||
|
||
// 支持键盘选择的列表 | ||
export const KeyboardSelectableList = (props: { | ||
items: { description: string; command: string }[]; | ||
handleSuggestionClick: (command: string) => void; | ||
controller?: Emitter<string>; | ||
noListen?: boolean; | ||
}) => { | ||
const { items, handleSuggestionClick, noListen = false, controller } = props; | ||
// 选中项的索引,默认为最后一个 | ||
const [selectedIndex, setSelectedIndex] = useState(-1); | ||
|
||
// 处理键盘事件 | ||
const handleKeyPress = (event: KeyboardEvent) => { | ||
switch (event.key) { | ||
case 'ArrowUp': // 上键 | ||
setSelectedIndex((prevIndex) => Math.max(prevIndex - 1, 0)); | ||
break; | ||
case 'ArrowDown': // 下键 | ||
setSelectedIndex((prevIndex) => | ||
Math.min(prevIndex + 1, items.length - 1), | ||
); | ||
break; | ||
case 'Enter': // 回车键 | ||
if (items[selectedIndex]) { | ||
handleSuggestionClick(items[selectedIndex].command); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
// 添加全局键盘事件监听器 | ||
useEffect(() => { | ||
if (noListen) {return;} | ||
window.addEventListener('keydown', handleKeyPress); | ||
return () => { | ||
window.removeEventListener('keydown', handleKeyPress); | ||
}; | ||
}, [items, selectedIndex]); | ||
|
||
useEffect(() => { | ||
if (!controller) {return;} | ||
const disposable = controller.event((e: string) => { | ||
if (e === 'ArrowUp') { | ||
setSelectedIndex((prevIndex) => Math.max(prevIndex - 1, 0)); | ||
} | ||
if (e === 'ArrowDown' || e === 'Tab') { | ||
setSelectedIndex((prevIndex) => | ||
Math.min(prevIndex + 1, items.length - 1), | ||
); | ||
} | ||
if (e === 'Enter') { | ||
if (items[selectedIndex]) { | ||
handleSuggestionClick(items[selectedIndex].command); | ||
} | ||
} | ||
}); | ||
|
||
return () => { | ||
disposable.dispose(); | ||
}; | ||
}, [controller, selectedIndex, items]); | ||
|
||
useEffect(() => { | ||
// HACK 定位到顶部 | ||
setSelectedIndex(0); | ||
}, [items]); | ||
|
||
return ( | ||
<div className={styles.suggestions}> | ||
{items.map((cmd, index) => ( | ||
<div | ||
key={index} | ||
className={styles.suggestionItem} | ||
style={{ backgroundColor: index === selectedIndex ? 'var(--selection-background)' : '' }} | ||
onClick={() => handleSuggestionClick(cmd.command)} | ||
> | ||
<div className={styles.suggestionItemContainer}> | ||
<div className={styles.suggestionDesc}>{cmd.description}</div> | ||
<div className={styles.suggestionCmd}>{cmd.command}</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export const TerminalIntellCommandController = (props: { | ||
suggestions: SmartCommandDesc[]; | ||
controller: Emitter<string>; | ||
onSuggestion: (suggestion: string) => void; | ||
}) => { | ||
const { suggestions, controller, onSuggestion } = props; | ||
|
||
return ( | ||
<div style={{ position: 'relative' }}> | ||
{suggestions.length > 0 && ( | ||
<KeyboardSelectableList | ||
items={suggestions} | ||
controller={controller} | ||
handleSuggestionClick={onSuggestion} | ||
noListen | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
91 changes: 91 additions & 0 deletions
91
packages/terminal-next/src/browser/component/terminal-intell-complete-controller.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
.suggestions { | ||
display: flex; | ||
background-color: transparent; | ||
position: absolute; | ||
bottom: 100%; | ||
left: 0; | ||
|
||
// TODO 考虑动态设置字体 | ||
font-family: Menlo, Monaco, 'Courier New', monospace; | ||
z-index: 12; | ||
} | ||
|
||
.suggestionList { | ||
display: flex; | ||
flex-direction: column; | ||
max-height: 200px; | ||
width: 450px; | ||
overflow-y: scroll; | ||
border-radius: 8px; | ||
background-color: var(--vscode-editorSuggestWidget-background); | ||
color: var(--vscode-editorSuggestWidget-foreground); | ||
// TODO 适配白色主题 | ||
box-shadow: rgba(0, 0, 0, 0.133) 0px 3.2px 7.2px 0px, rgba(0, 0, 0, 0.11) 0px 0.6px 1.8px 0px; | ||
} | ||
|
||
.suggestionItem { | ||
padding: 8px 10px 8px 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.suggestionItemContainer { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.suggestionDesc { | ||
font-size: 11px; | ||
opacity: 0.6; | ||
margin-left: 8px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.suggestionIcon { | ||
margin-right: 8px; | ||
} | ||
|
||
.suggestionCmd { | ||
font-size: 12px; | ||
white-space: nowrap; | ||
flex: 1; | ||
} | ||
|
||
.suggestionItem:hover { | ||
// filter: brightness(110%); | ||
// background-color: var(--selection-background); | ||
} | ||
|
||
// 选中时旁边展示详情的容器 | ||
.suggestionItemExtraContainer { | ||
background-color: #333; | ||
color: #fff; | ||
padding: 10px; | ||
border-radius: 4px; | ||
width: 300px; | ||
|
||
position: fixed; /* 全局定位 */ | ||
top: 0; | ||
transform: translateY(0); /* 修正浮动层位置 */ | ||
|
||
&.extraContainerLeft { | ||
left: 100%; /* 在列表项的右侧 */ | ||
margin-left: 10px; | ||
} | ||
|
||
&.extraContainerRight { | ||
right: 100%; /* 在列表项的左侧 */ | ||
margin-right: 10px; | ||
} | ||
} | ||
|
||
.suggestionItemExtraCommand { | ||
font-weight: bold; | ||
margin-bottom: 8px; | ||
font-size: 14px; | ||
} | ||
|
||
.suggestionItemExtraDescription { | ||
opacity: 0.6; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调整成 opensumi 全局用的 font-family 吧,代码库里搜一下