Skip to content

Commit 257fc24

Browse files
committed
change: read vscode settings to get to format
1 parent 88620e8 commit 257fc24

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to the "flr" extension will be documented in this file.
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7-
## [Unreleased]
7+
## [0.0.7]
88

9-
- Initial release
9+
- read vscode settings to get `dart.lineLength` to format `r.g.dart`
10+
11+
## [0.0.6]
12+
13+
- Initial release

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "flr",
44
"displayName": "FLR",
55
"description": "Flutter Resources Manager",
6-
"version": "0.0.6",
6+
"version": "0.0.7",
77
"repository": "https://github.com/Fly-Mix/flr-vscode-extension",
88
"engines": {
99
"vscode": "^1.41.0"

src/resource-generator.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "fs";
44
import * as yaml from "js-yaml";
55
import * as flrPathMan from "./folder-manager";
66
import * as utils from "./utils";
7+
const os = require("os");
78

89
export class ResourceGenerator {
910
static namePool: string[] = new Array();
@@ -161,7 +162,32 @@ export class ResourceGenerator {
161162
content += textBlock;
162163

163164
fs.writeFileSync(file, content);
164-
utils.execute(`dartfmt -l 100 -w ${file}`);
165+
166+
/// read line length settings for dart and format
167+
let platform = process.platform;
168+
var settingFilePath = "";
169+
let settingFile = "Code/User/settings.json";
170+
/// https://vscode.readthedocs.io/en/latest/getstarted/settings/
171+
if (platform === "win32" && process.env.APPDATA !== undefined) {
172+
// windows
173+
settingFilePath = path.join(process.env.APPDATA, settingFile);
174+
} else if (platform === "darwin") {
175+
// macOS
176+
settingFilePath = `${os.homedir()}/Library/Application Support/${settingFile}`;
177+
} else {
178+
// linux
179+
settingFilePath = `${os.homedir()}/.config/${settingFile}`;
180+
}
181+
182+
let settings = fs.readFileSync(settingFilePath, "utf8");
183+
let json = JSON.parse(settings);
184+
let ll = json["dart.lineLength"];
185+
var lineLength = 80;
186+
if (ll !== null && ll !== undefined) {
187+
lineLength = parseInt(ll);
188+
}
189+
190+
utils.execute(`flutter format -l ${lineLength} ${file}`);
165191
} catch (e) {
166192
console.log(e);
167193
}

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export async function execute(command: string): Promise<string> {
1616
export enum Names {
1717
generatedFileName = "r.g.dart",
1818
flr = "flr",
19-
pubspec = "pubspec.yaml"
19+
pubspec = "pubspec.yaml",
20+
settings = "settings.json"
2021
}
2122

2223
export enum Commands {

0 commit comments

Comments
 (0)