邪魅是什么意思| 明矾有什么作用| 前胸后背疼是什么病| 住院报销需要什么材料| 腹主动脉钙化是什么意思| 脖子上有痣代表什么| 中药吃多了对人体有什么伤害| 生姜泡醋有什么功效| 芳菲是什么意思| 检查肝肾功能挂什么科| 看乳腺应该挂什么科| 吃地瓜叶有什么好处和坏处| 什么水花| 破伤风感染后会出现什么症状| 66年属马的是什么命| 缺维生素b有什么症状| 常喝柠檬水有什么好处和坏处| 穿云箭是什么意思| 冰心原名什么| 下嘴唇溃疡是什么原因| 红细胞减少是什么原因| 为什么会长智齿| 伤口愈合慢是什么原因| 肺气肿用什么药效果好| 孕妇拉肚子是什么原因引起的| 幼儿急疹是什么原因引起的| 下巴下面长痘痘是什么原因| 4pcs是什么意思| 哈达是什么意思| 两个a型血的人生的孩子什么血型| 啵啵是什么| 嘌呤是什么东西| 囊性灶什么意思严重吗| 不耐受和过敏有什么区别| 天使综合征是什么病| bmp是什么意思| uspa是什么牌子| 脚踝发黑是什么原因| cross是什么牌子| 彩超跟b超有什么区别| 苍龙七宿的秘密是什么| 脾虚吃什么好| 出其不意下一句是什么| lookbook是什么意思| 黑皮肤适合穿什么颜色的衣服| 1月11日是什么星座| 紫癜是什么| 粉刺是什么东西| 堂客是什么意思| 眼袋肿了是什么原因| 芦芽是什么| 经期便秘是什么原因| 口业是什么意思| 野合什么意思| 盆腔b超检查什么| 世界第一大运动是什么| 梦到蛇是什么征兆| 怕冷畏寒是什么原因| 40什么意思| 查摆是什么意思| 鸭肉不能和什么一起吃| 皮肤瘙痒症用什么药| 颐养天年是什么意思| 风花雪月下一句是什么| er是什么元素| 免疫力差吃什么| plg是什么意思| 吴亦凡为什么退出exo| 脾胃虚弱吃什么蔬菜| dragon是什么意思| pyq是什么意思| 95年的猪是什么命| 去火吃什么水果| 菊花代表什么象征意义| 3月20号是什么星座| 慢性咽炎是什么症状| 吃什么补肾气| 四方草地是什么生肖| 芦芽是什么| 不够时间好好来爱你是什么歌| 为什么会中暑| 黑色皮肤适合什么颜色的衣服| 拉血挂什么科| 全套是什么| 早上空腹喝淡盐水有什么好处| 做颈动脉彩超挂什么科| 做胃镜之前需要注意什么| 梦见抓了好多鱼是什么意思| 炸肺是什么意思| 女人送男人打火机代表什么| 血管瘤是什么病严重吗| 脂肪肝要注意什么| 煸是什么意思| 紫罗兰色是什么颜色| 春回大地是什么生肖| 吃火龙果对身体有什么好处| 利血平是什么药| 酸奶有什么好处| 利多卡因是什么药| 妈妈的表妹叫什么| 什么是天丝| 10000是什么电话| 125是什么意思| 正月二十是什么星座| 孕妇白细胞高是什么原因| 96345是什么电话| 木辛读什么| 大电念什么| 预防保健科是做什么的| 皮肤变黑是什么原因| 腰椎生理曲度存在是什么意思| 尿酸看什么科| 鱼肝油什么时候吃最好| 22岁属什么| 什么是经络| 小孩支气管炎吃什么药| 手信是什么| 鞋底md是什么材质| 什么事情| 小孩发烧流鼻血是什么原因| 放屁臭是什么原因| 心什么诚服| 三个代表代表了什么| 舌头两边疼是什么原因| 六月不搬家是什么意思| 才高八斗是指什么生肖| 崛起是什么意思| 鸡毛菜是什么菜| 拿到offer是什么意思| 舌炎是什么原因引起的怎样治疗| 情绪波动是什么意思| 贞操带是什么| 眼角有眼屎是什么原因| 乳岩是什么病| 歇夏是什么意思| 打呼噜是什么病| 顶格是什么意思| 为什么耳鸣| 红茶加枸杞有什么功效| 杜比全景声是什么意思| 咳嗽喉咙痒吃什么药好得快| 肚脐左侧是什么器官| 风麻疹是什么引起的| edp是什么意思| 什么手| 女性尿浑浊是什么原因| 木糖醇是什么糖| 金克什么| au999是什么金| 萎缩性胃炎不能吃什么食物| hpc是什么| 经期适合喝什么茶| 上车饺子下车面什么意思| 女人梦见龙是什么征兆| 慰藉是什么意思| 小孩流口水是什么原因| 糜烂性脚气用什么药| pt是什么材质| 什么样的你| 宝姿是什么档次的牌子| 夏天为什么要吃姜| 人为什么怕蛇| 中性粒细胞比率偏高是什么意思| 范思哲香水是什么档次| 肝火上炎吃什么中成药| 螺旋杆菌是什么病| butterfly什么意思| 韭菜什么时候种最合适| 下面有味道用什么药| 令羽读什么| 味精是什么做的| 孕妇吸氧对胎儿有什么好处| 为什么白带是绿色| 老是犯困是什么原因| 舌苔发白是什么原因| 县尉相当于现在什么官| 低密度脂蛋白高有什么症状| 灰白组织是什么意思| 白细胞低有什么危险| 玉谷叶是什么植物| 哈萨克斯坦是什么人种| 腊肉配什么菜炒好吃| 龙虎山是什么地貌| 痔疮术后吃什么恢复快| 睡觉头出汗是什么原因| 上火喝什么比较好| 布洛芬是什么药| 直肠炎是什么症状| 贫血吃什么补| 腰疼不能弯腰是什么原因引起的| 皮肤癣用什么药| 甲醛中毒有什么症状| 4个火读什么| 吞咽困难是什么感觉| 半月板退变是什么意思| prog是什么意思| 本番是什么意思| 婴儿流鼻涕吃什么药| 葡萄球菌感染是什么原因引起的| 肝实质密度减低是什么意思| 四月二号是什么星座| 宁的五行属性是什么| 内分泌紊乱是什么症状| 风湿什么药好| 身份证最后四位数代表什么| 雪霁是什么意思| 头皮发白是什么原因| 白露是什么时候| 画是什么生肖| 心绪不宁的意思是什么| 成吉思汗什么意思| 七夕什么时候| 水瓶座女生和什么星座男生最配| 屁多还臭是什么原因| 男人吃六味地黄丸有什么好处| 什么斗艳| 脂蛋白高说明什么问题| 做阴超有黄体说明什么| 腰闪了挂什么科| 为什么吃一点东西肚子就胀| junior什么意思| 8月23号是什么星座| 与世隔绝的绝是什么意思| 吃什么可以拉肚子通便| 作灶是什么意思| 外泌体是什么| 儿童手指头脱皮什么原因引起的| swan什么意思| 三点水者念什么意思| 北极为什么没有企鹅| 什么品牌奶粉好消化| 脖子疼吃什么药| 88年属什么的| 豕是什么动物| 偏心是什么意思| 扁肉是什么| rh阴性血是什么血型| 103是什么意思| 突然出汗是什么原因| 无什么| 吃槟榔有什么好处| 鼻子出油多是什么原因| 夏天喝什么汤好| 失眠可以吃什么药| 挖墙脚是什么意思| 乳头瘤病毒是什么意思| 中国文字博大精深什么意思| 阴道瘙痒吃什么药| eur是什么意思| 被蜜蜂蛰了涂什么药膏| 什么是adhd| 感冒冒虚汗是什么原因| 重要是什么意思| 肝脏不好吃什么药| 党什么时候成立| 8月15是什么星座| ct什么意思| 见到黑猫代表什么预兆| 人不出汗是什么原因| 肾结石忌口什么| 耳鸣吃什么药效果最好| 什么叫早搏| 双侧基底节区腔隙灶是什么意思| 四库是指什么| 百度

Try to extend agent mode in VS Code!

中共浙江警察学院委员会关于巡视整改情况的通报

百度   制度创新以人民利益为本位。

Source code refactoring can improve the quality and maintainability of your project by restructuring your code, while not modifying the runtime behavior. Visual Studio Code supports refactoring operations (refactorings) such as Extract Method and Extract Variable to improve your codebase from within the editor.

refactoring hero image

For example, a common refactoring used to avoid duplicating code (a maintenance headache) is the Extract Method refactoring, where you select source code and pull it out into its own shared method, so that can reuse the code elsewhere.

Refactorings are provided by a language service. VS Code has built-in support for TypeScript and JavaScript refactoring through the TypeScript language service. Refactoring support for other programming languages is enabled through VS Code extensions that contribute language services.

The UI elements and VS Code commands for refactoring are the same across the different languages. This article demonstrates refactoring support in VS Code with the TypeScript language service.

Code Actions = Quick Fixes and refactorings

In VS Code, Code Actions can provide both refactorings and Quick Fixes for detected issues (highlighted with red squiggles). When the cursor is on a squiggle or on a selected text region, VS Code shows a light bulb icon in the editor to indicate that a Code Action is available. If you select the Code Action light bulb or use the Quick Fix command ?. (Windows, Linux Ctrl+.), the Quick Fixes and refactorings control is presented.

If you prefer to only see refactorings without Quick Fixes, then you can use the Refactor command (??R (Windows, Linux Ctrl+Shift+R)).

Note: You can completely disable Code Action lightbulbs in the editor with the editor.lightbulb.enable setting. You can still open Quick Fixes through Quick Fix command and ?. (Windows, Linux Ctrl+.) keyboard shortcut.

Code Actions on save

With the editor.codeActionsOnSave setting, you can configure a set of Code Actions that are automatically applied when you save a file, for example to organize imports. Based on your workspace files and active extensions, IntelliSense provides a list of available Code Actions.

Screenshot of settings.json, showing IntelliSense suggestions for the editor.codeActionsOnSave setting.

You can configure one or more Code Actions for editor.codeActionsOnSave. The Code Actions are then run in the order they're listed.

The following example shows how to configure multiple Code Actions on save:

// On explicit save, run sortImports source action. On auto save (window or focus change), run organizeImports source action.
"editor.codeActionsOnSave": {
    "source.organizeImports": "always",
    "source.sortImports": "explicit",
},

The following values are supported for each Code Action:

  • explicit (default): Triggers Code Actions when explicitly saved
  • always: Triggers Code Actions when explicitly saved and on Auto Saves from window or focus changes
  • never: Never triggers Code Actions on save
Note

Although true and false are still valid configuration values at the moment, they will be deprecated in favor of explicit, always, and never.

Refactoring actions

Extract Method

Select the source code you'd like to extract and then select the light bulb in the gutter or press (?. (Windows, Linux Ctrl+.)) to see available refactorings. Source code fragments can be extracted into a new method, or into a new function at various different scopes. During the extract refactoring, you are prompted to provide a meaningful name.

Extract Variable

The TypeScript language service provides Extract to const refactoring to create a new local variable for the currently selected expression:

Extract local

When working with classes, you can also extract a value to a new property.

Rename symbol

Renaming is a common operation related to refactoring source code, and VS Code has a separate Rename Symbol command (F2). Some languages support renaming a symbol across files. Press F2, type the new desired name, and press Enter. All instances of the symbol across all files will be renamed.

Rename

Refactor Preview

When you apply a refactoring, the changes are directly implemented to your code. In the Refactor Preview panel, you can preview the changes that will be applied by a refactoring operation.

To open the Refactor Preview panel, open the Code Actions control, hover over a refactoring, and then press ?Enter (Windows, Linux Ctrl+Enter).

Video of launching the Refactor Preview panel by pressing  on the Code Actions control.

You can select any of the changes in the Refactor Preview panel to get a diff view of the changes that are a result of the refactoring operation.

Screenshot of the Refactor Preview panel that shows an 'Extract to' refactoring that results in two changes

Use the Accept or Discard controls to apply or cancel the proposed refactoring changes.

Optionally, you can partially apply the refactoring changes by deselecting some of the proposed changes in the Refactor Preview panel.

Screenshot of the Refactor Preview panel that shows how to partially apply changes by deselecting specific changes.

Keyboard shortcuts for Code Actions

The editor.action.codeAction command lets you configure keyboard shortcuts for specific Code Actions. This keyboard shortcut, for example, triggers the Extract function refactoring Code Actions:

{
  "key": "ctrl+shift+r ctrl+e",
  "command": "editor.action.codeAction",
  "args": {
    "kind": "refactor.extract.function"
  }
}

Code Action kinds are specified by extensions using the enhanced CodeActionProvider API. Kinds are hierarchical, so "kind": "refactor" shows all refactoring Code Actions, whereas "kind": "refactor.extract.function" only shows Extract function refactorings.

Using the above keyboard shortcut, if only a single "refactor.extract.function" Code Action is available, it is automatically applied. If multiple Extract function Code Actions are available, VS Code brings up a context menu to select them:

Select Code Action context menu

You can also control how and when Code Actions are automatically applied by using the apply argument:

{
  "key": "ctrl+shift+r ctrl+e",
  "command": "editor.action.codeAction",
  "args": {
    "kind": "refactor.extract.function",
    "apply": "first"
  }
}

Valid values for apply:

  • first - Always automatically apply the first available Code Action.
  • ifSingle - (Default) Automatically apply the Code Action if only one is available. Otherwise, show the context menu.
  • never - Always show the Code Action context menu, even if only a single Code Action is available.

When a Code Action keyboard shortcut is configured with "preferred": true, only preferred Quick Fixes and refactorings are shown. A preferred Quick Fix addresses the underlying error, while a preferred refactoring is the most common refactoring choice. For example, while multiple refactor.extract.constant refactorings might exist, each extracting to a different scope in the file, the preferred refactor.extract.constant refactoring is the one that extracts to a local variable.

This keyboard shortcut uses "preferred": true to create a refactoring that always tries to extract the selected source code to a constant in the local scope:

{
  "key": "shift+ctrl+e",
  "command": "editor.action.codeAction",
  "args": {
    "kind": "refactor.extract.constant",
    "preferred": true,
    "apply": "ifSingle"
  }
}

Extensions with refactorings

You can find extensions that support refactoring by looking in the VS Code Marketplace. You can go to the Extensions view (??X (Windows, Linux Ctrl+Shift+X)) and type 'refactor' in the search box. You can then sort by install count or ratings to see which extensions are popular.

Tip: The extensions shown above are dynamically queried. Select an extension tile above to read the description and reviews to decide which extension is best for you.

Next steps

Common questions

Why don't I see any light bulbs when there are errors in my code?

Light bulbs (Code Actions) are only shown when the cursor is over the text showing the error. Hovering over the text shows the error description, but you need to move the cursor or select text to see light bulbs for Quick Fixes and refactorings.

左脸颊有痣代表什么 红斑狼疮是什么病 牙龈肿痛用什么药好得快 心率90左右意味着什么 舅舅的爸爸叫什么
冬天什么 桂皮是什么树的皮 打太极拳有什么好处 禾花鱼是什么鱼 medium什么意思
脉沉细是什么意思 过敏性鼻炎喷什么药 2.4什么星座 清道夫吃什么 尿是绿色的是什么原因
牙疼脸肿了吃什么药 警示是什么意思 打酱油是什么意思 临床医学学什么 出炉是什么意思
经期吃什么让血量增加hcv8jop6ns9r.cn 肱骨头小囊变什么意思hcv7jop7ns3r.cn 具象是什么意思hcv9jop0ns5r.cn 脑梗应该挂什么科hcv8jop8ns6r.cn 有利有弊是什么意思hcv9jop4ns3r.cn
1967年出生属什么hcv9jop0ns0r.cn 嗓子痛什么原因ff14chat.com 什么是信念youbangsi.com 探病是什么意思xscnpatent.com 同人文是什么意思hcv8jop9ns4r.cn
慰问金是什么意思hcv8jop6ns8r.cn 玄关挂什么装饰画好hcv7jop6ns6r.cn 血色素是什么意思hcv7jop6ns0r.cn 什么是婚检hcv9jop5ns2r.cn 备孕不应该吃什么shenchushe.com
吃什么容易消化hcv9jop1ns0r.cn 二月二十一是什么星座hcv9jop0ns0r.cn 开天辟地是什么生肖cj623037.com 肾轻度积水是什么意思hcv8jop9ns5r.cn 北京市长是什么级别hkuteam.com
百度