Vscode: Remove some deprecated code in ./src/vs/base

Created on 28 Jul 2020  路  27Comments  路  Source: microsoft/vscode



I find that following methods are deprecated:

7 results - 2 files

src/vs/base/browser/dom.ts:
  74  };
  75  
  76: /** @deprecated ES6 - use classList*/
  77  export function hasClass(node: HTMLElement | SVGElement, className: string): boolean { return _classList.hasClass(node, className); }
  78: /** @deprecated ES6 - use classList*/
  79  export function addClass(node: HTMLElement | SVGElement, className: string): void { return _classList.addClass(node, className); }
  80: /** @deprecated ES6 - use classList*/
  81  export function addClasses(node: HTMLElement | SVGElement, ...classNames: string[]): void { return _classList.addClasses(node, ...classNames); }
  82: /** @deprecated ES6 - use classList*/
  83  export function removeClass(node: HTMLElement | SVGElement, className: string): void { return _classList.removeClass(node, className); }
  84: /** @deprecated ES6 - use classList*/
  85  export function removeClasses(node: HTMLElement | SVGElement, ...classNames: string[]): void { return _classList.removeClasses(node, ...classNames); }
  86: /** @deprecated ES6 - use classList*/
  87  export function toggleClass(node: HTMLElement | SVGElement, className: string, shouldHaveIt?: boolean): void { return _classList.toggleClass(node, className, shouldHaveIt); }
  88  

src/vs/base/common/strings.ts:
  15  
  16  /**
  17:  * @deprecated ES6: use `String.padStart`
  18   */
  19  export function pad(n: number, l: number, char: string = '0'): string {

I'd like to send a pull request to remove these deprecated methods and refactor all usages if you want.

debt

Most helpful comment

I've deleted strings#pad.

All 27 comments

Starting from @mjbvz , not sure where the deprecation information are from.

I'd like to send a pull request to remove these deprecated methods

:-1: We do not accept pull requests like that

This is driven from .vscode/searches/es6.code-search and each and every user of the listed functions needs to become active.

The classList usage is usually a big change, the others should be small... Starting with @joaomoreno, please pass it on to the next person

@jrieken I am out this month... sorry.

Remaining:

src/vs/base/common/strings.ts

  • [x] pad
  • [x] startsWith
  • [x] endsWith
  • [x] repeat

src/vs/base/common/objects.ts

  • [x] 聽assign

src/vs/base/browser/dom.ts

  • [x] removeNode
  • [x] hasClass and friends

src/vs/base/common/arrays.ts

  • [x] first
  • [x] find

I have replaced my usages of the deprecated code. I believe I have cought all places, however if some remain feel free to ping me.
Assigning this to @joaomoreno since I saw a lot of usages in our widgets, though feel free to pass it on to the next person.

Here's a useful find/replace input pair, for text based refactoring:

(add|remove|toggle)Class\(([^,]+), 
$2.classList.$1(

The unfortunate choice of having multiple class names on a single string Codicon.classNames: string and having DOM.addClass support that is the hardest problem here. Going with simple refactoring, powered by TypeScript, you immediately hit very bad things:

image

After looking at all references from here, I believe I got a good picture of the top 4 people who would do most of the rest of the changes: @sbatten @bpasero @jrieken @alexdima .

Again, be aware of codicons, which use multiple classes in a single string and classList.add will blow up in your face whenever it sees whitespace.

@joaomoreno I missed it, what should I do if my class contains a space?

Hmm I see that strings.pad is deprecated in favor of String.padStart. But they do not have the same functionality. Am I missing something here?
Code pointer https://github.com/microsoft/vscode/blob/fcb916f02c49a05a841663f319b8d9dbb3ee2daa/src/vs/base/common/strings.ts#L19

Isn't strings.pad(1, 10, '0') === String(1).padStart(10, '0')

@jrieken thanks. I have misread the method.

I believe the change I just pushed removes the last usages of removeNode

I don't think I own any of the remaining ones but I went through hasClass across all usages, I think it's better someone just does them all:

image

@bpasero there was still some usage of the strings#repeat in your land

@jrieken can you point me to that code please

src/vs/platform/diagnostics/node/diagnosticsService.ts you were the last to touch it

@RMacfarlane can you please see https://github.com/microsoft/vscode/commit/02710ecca2d675e98e411f07a2f8879ffc3aba41 if it works as you intended it, I think you are the original author.

Thanks @bpasero, your changes look good!

almost there... @joaomoreno @alexdima @sandy081 @mjbvz for strings#pad

I've deleted strings#pad.

Remaining (all under dom.ts):

  • [ ] [addClass](https://github.com/microsoft/vscode/blob/cd2a92ae134d4eb20f20f8f6250a4a89c86e7abb/src/vs/base/browser/dom.ts#L72)
  • [x] [addClasses](https://github.com/microsoft/vscode/blob/cd2a92ae134d4eb20f20f8f6250a4a89c86e7abb/src/vs/base/browser/dom.ts#L72)
  • [x] [removeClasses](https://github.com/microsoft/vscode/blob/cd2a92ae134d4eb20f20f8f6250a4a89c86e7abb/src/vs/base/browser/dom.ts#L72)
  • [ ] [toggleClass](https://github.com/microsoft/vscode/blob/cd2a92ae134d4eb20f20f8f6250a4a89c86e7abb/src/vs/base/browser/dom.ts#L72)

@joaomoreno Assigning you to start. Please reassign to correct owners for this

  • Terminal @Tyriar
  • Webview @mjbvz
  • Scrollbar @alexdima
  • Lightbulb Widget @aeschli
  • Workbench Theme Service @aeschli

oh, wow actually done

馃憦 and thanks everyone involved here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trstringer picture trstringer  路  3Comments

shanalikhan picture shanalikhan  路  3Comments

ryan-wong picture ryan-wong  路  3Comments

omidgolparvar picture omidgolparvar  路  3Comments

curtw picture curtw  路  3Comments