Skip to content

Commit 0ebff48

Browse files
authored
Merge pull request #43 from MetamediaTechnology/refactoring
Refactoring
2 parents 0094557 + 46419cf commit 0ebff48

7 files changed

Lines changed: 240 additions & 100 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [Released]
88
### [0.2.10] : 13/04/2568
9-
- refactor: Can using the extension with default key
9+
- refactor: Can use the extension with default key
1010

1111
### [0.2.9] : 22/04/2568
1212
- refactor: Improved notification for better experience.

README.md

Lines changed: 175 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
1-
# Longdo Spell Checker for VS Code
1+
# Longdo Spell Checker for VS Code
22

33
![Build Status](https://github.com/MetamediaTechnology/vscode-longdo-spell-checker/actions/workflows/node.js.yml/badge.svg)
44

55
Longdo Spell Checker is a VSCode extension for Thai spell checking. It highlights errors and suggests corrections, helping you write accurate Thai text effortlessly. 🚀
66

77
![Longdo Spell Checker](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/preview.gif)
88

9-
---
9+
## 🌐 Language / ภาษา
10+
- [English](#english)
11+
- [ภาษาไทย](#ภาษาไทย)
1012

11-
## 🔧 Installation
13+
## English
14+
15+
### 🔧 Installation
16+
17+
### 1. Get an API Key (Free)
1218

13-
### 1. Get an API Key (Free)
1419
To use Longdo Spell Checker, you need an API key, which allows up to **100,000 free requests per month**.
1520
🔗 **Register for free** at [Longdo Account](https://map.longdo.com/console/).
1621
![LongdoConsole](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/setup_3.png)
1722

18-
### 2. Configure the API Key
19-
Choose one of the following methods:
23+
### 2. Configure the API Key
2024

21-
#### **Option 1: Set via VS Code Settings**
22-
1. Open **VS Code Settings**
23-
- **Windows/Linux:** `File > Preferences > Settings`
24-
- **MacOS:** `Code > Preferences > Settings`
25-
2. Search for **"Longdo Spell Checker"**
26-
3. Enter your **API Key**
25+
Choose one of the following methods:
26+
27+
#### **Option 1: Set via VS Code Settings**
2728

28-
![Settings](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/setup_1.png)
29+
1. Open **VS Code Settings**
30+
- **Windows/Linux:** `File > Preferences > Settings`
31+
- **MacOS:** `Code > Preferences > Settings`
32+
2. Search for **"Longdo Spell Checker"**
33+
3. Enter your **API Key**
2934

30-
#### **Option 2: Set via `settings.json`**
31-
1. Open **settings.json**
32-
- **Windows/Linux:** `File > Preferences > Settings` > Click `{}` (top right)
33-
- **MacOS:** `Code > Preferences > Settings` > Click `{}` (top right)
34-
2. Add the following configuration:
35+
![Settings](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/setup_1.png)
36+
37+
#### **Option 2: Set via `settings.json`**
38+
39+
1. Open **settings.json**
40+
- **Windows/Linux:** `File > Preferences > Settings` > Click `{}` (top right)
41+
- **MacOS:** `Code > Preferences > Settings` > Click `{}` (top right)
42+
2. Add the following configuration:
3543
```json
3644
"longdo-spell-checker.apiKey": "YOUR_API_KEY"
37-
```
45+
```
46+
47+
---
3848

39-
---
49+
## ✨ How to Use
4050

41-
## ✨ How to Use
51+
### **Using the UI**
4252

43-
### **Using the UI**
44-
Once installed, you’ll see **Longdo Spell** in the **status bar (bottom right)**.
45-
- Click on it to access options such as **Check Spelling (Current Tab)** or **Clear All Errors (Current Tab)**.
53+
Once installed, you'll see **Longdo Spell** in the **status bar (bottom right)**.
4654

47-
### 🎯 **Using Commands**
48-
1. Open the **Command Palette**:
49-
- **Windows/Linux:** `Ctrl + Shift + P`
50-
- **MacOS:** `Cmd + Shift + P`
51-
2. Type and select:
52-
- `Longdo Spell Checker: Check Spelling (Current Tab)` → Check spelling
53-
- `Clear All Errors (Current Tab)` → Clear suggestions
55+
- Click on it to access options such as **Check Spelling (Current Tab)** or **Clear All Errors (Current Tab)**.
56+
57+
### 🎯 **Using Commands**
58+
59+
1. Open the **Command Palette**:
60+
- **Windows/Linux:** `Ctrl + Shift + P`
61+
- **MacOS:** `Cmd + Shift + P`
62+
2. Type and select:
63+
- `Longdo Spell Checker: Check Spelling (Current Tab)` → Check spelling
64+
- `Clear All Errors (Current Tab)` → Clear suggestions
5465

5566
---
5667

57-
## 💡 Features
68+
## 💡 Features
5869

5970
**Thai spell checking with suggestions**
6071
**Quick fix for spelling errors**
@@ -64,43 +75,150 @@ Once installed, you’ll see **Longdo Spell** in the **status bar (bottom right)
6475

6576
---
6677

67-
## 🌏 Language Support
78+
## 🌏 Language Support
6879

69-
| Language | Support Level |
70-
|----------|------------------------------|
71-
| 🇹🇭 Thai |Full Support |
80+
| Language | Support Level |
81+
| ---------- | -------------------------- |
82+
| 🇹🇭 Thai | Full Support |
7283
| 🇬🇧 English | JSON, Markdown, JavaScript |
7384

74-
---
7585

76-
## 📂 Supported File Extensions
86+
## 📜 Terms of Use
87+
88+
The extension **requires an API key** because spell checking is processed on a server.
89+
90+
- **Free Tier**: 100,000 requests/month
91+
- **Text Limit**: If your text exceeds **1,024 characters**, it will be split into multiple requests.
92+
93+
📌 Example:
94+
95+
- A **1,025-character** text = **2 requests**
96+
- A **5,000-character** text = **5 requests**
97+
-
98+
## 🔒 Privacy
99+
100+
### Data Processing
101+
- All text checking is processed on [Longdo servers](https://longdo.com/)
102+
- We do not store your text content permanently
103+
- Text is only used for spell checking purposes
104+
105+
### Data Collection
106+
- We collect anonymous usage statistics to improve the service
107+
- This includes:
108+
- Number of requests
109+
- Size of content checked
110+
- Types of errors detected
111+
112+
### Data Security
113+
- All data is transmitted securely through HTTPS
114+
- API keys are used only to authenticate requests
115+
- No personal information is required beyond the API key
116+
117+
118+
🔗 **Register for an API Key:** [Longdo Console](https://map.longdo.com/console/) (It's free!)
119+
120+
## ภาษาไทย
121+
122+
## 🛠️ การติดตั้ง
123+
124+
### 1. ขอรับ API Key (ฟรี)
125+
126+
เพื่อใช้งาน Longdo Spell Checker คุณจำเป็นต้องมี API Key ซึ่งจะให้สิทธิ์ใช้งานฟรีสูงสุด **100,000 ครั้งต่อเดือน**
127+
128+
🔗 **สมัครใช้งานฟรี** ได้ที่ [Longdo Account](https://map.longdo.com/console/)
129+
![LongdoConsole](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/setup_3.png)
130+
131+
> โดยปกติแล้วหากไม่ตั้งค่า API KEY ท่านสามารถใช้งานได้ฟรี โดยจะนับการใช้งานรวมกับบุคคลอื่น
77132
78-
| File Type | Supported |
79-
|------------|-----------|
80-
| Markdown (.md), JavaScript (.js), TypeScript (.ts) ||
81-
| Python (.py), PHP (.php), Vue (.vue), Go (.go) ||
82-
| HTML (.html), CSS (.css), JSON (.json), Dart (.dart) ||
83-
| Ruby (.rb), Java (.java), C (.c), C++ (.cpp) ||
84-
| C# (.cs), XML (.xml), YAML (.yml/.yaml), Plain Text (.txt) ||
85-
| Shell Script (.sh), SQL (.sql), Rust (.rs) ||
133+
### 2. ตั้งค่า API Key
134+
135+
เลือกวิธีใดวิธีหนึ่งในการตั้งค่าต่อไปนี้:
136+
137+
#### **วิธีที่ 1: ตั้งค่าผ่าน VS Code Settings**
138+
139+
1. เปิด **VS Code Settings**
140+
- **Windows/Linux:** `File > Preferences > Settings`
141+
- **MacOS:** `Code > Preferences > Settings`
142+
2. ค้นหาคำว่า **"Longdo Spell Checker"**
143+
3. กรอก **API Key** ของคุณ
144+
145+
![Settings](https://raw.githubusercontent.com/MetamediaTechnology/vscode-longdo-spell-checker/refs/heads/main/docs/setup_1.png)
146+
147+
#### **วิธีที่ 2: ตั้งค่าผ่าน `settings.json`**
148+
149+
1. เปิดไฟล์ **settings.json**
150+
- **Windows/Linux:** `File > Preferences > Settings` > คลิกที่ปุ่ม `{}` มุมขวาบน
151+
- **MacOS:** `Code > Preferences > Settings` > คลิกที่ปุ่ม `{}` มุมขวาบน
152+
2. เพิ่มค่าดังนี้ลงไปในไฟล์:
153+
```json
154+
"longdo-spell-checker.apiKey": "YOUR_API_KEY"
155+
```
86156

87157
---
88158

89-
## 📜 Terms of Use
159+
## ✨ วิธีใช้งาน
160+
161+
### ✅ **ใช้งานผ่าน UI**
162+
163+
หลังติดตั้งแล้ว จะมี **Longdo Spell** แสดงอยู่ที่ **แถบสถานะด้านล่างขวา**
90164

91-
The extension **requires an API key** because spell checking is processed on a server.
92-
- **Free Tier**: 100,000 requests/month
93-
- **Text Limit**: If your text exceeds **1,024 characters**, it will be split into multiple requests.
165+
- คลิกเพื่อเลือกตัวเลือก เช่น **ตรวจคำสะกดในแท็บปัจจุบัน** หรือ **ล้างข้อผิดพลาดทั้งหมด**
166+
167+
### 🎯 **ใช้งานผ่านคำสั่ง**
168+
169+
1. เปิด **Command Palette**
170+
- **Windows/Linux:** `Ctrl + Shift + P`
171+
- **MacOS:** `Cmd + Shift + P`
172+
2. พิมพ์และเลือกคำสั่งต่อไปนี้:
173+
- `Longdo Spell Checker: Check Spelling (Current Tab)` → ตรวจคำสะกด
174+
- `Clear All Errors (Current Tab)` → ล้างข้อเสนอแนะทั้งหมด
94175

95-
📌 Example:
96-
- A **1,025-character** text = **2 requests**
97-
- A **5,000-character** text = **5 requests**
176+
## 💡 ฟีเจอร์ที่รองรับ
98177

99-
🔗 **Register for an API Key:** [Longdo Console](https://map.longdo.com/console/) (It's free!)
178+
✅ **ตรวจคำสะกดภาษาไทย พร้อมคำแนะนำ**
179+
✅ **แก้ไขคำผิดแบบรวดเร็ว (Quick fix)**
180+
✅ **รองรับหลายประเภทไฟล์**
100181

101182
---
102183

103-
## 🔒 Privacy Policy
184+
## 🌏 ภาษาที่รองรับ
185+
186+
| ภาษา | ระดับการรองรับ |
187+
| ----------- | ------------------------------ |
188+
| 🇹🇭 ภาษาไทย | รองรับทุกนามสกุลไฟล์ |
189+
| 🇬🇧 ภาษาอังกฤษ | JSON, Markdown, JavaScript |
190+
191+
---
192+
193+
## 📜 เงื่อนไขการใช้งาน
194+
195+
ส่วนขยายนี้ **จำเป็นต้องใช้ API Key** เพราะการตรวจคำสะกดจะดำเนินการบนเซิร์ฟเวอร์
196+
197+
- **ฟรี:** ใช้งานได้ 100,000 ครั้ง/เดือน
198+
- **ข้อจำกัดของข้อความ:** ถ้าข้อความเกิน **1,024 ตัวอักษร** จะถูกแบ่งเป็นหลายคำขอ (request)
199+
200+
📌 ตัวอย่าง:
201+
202+
- ข้อความยาว **1,025 ตัวอักษร** = **2 คำขอ**
203+
- ข้อความยาว **5,000 ตัวอักษร** = **5 คำขอ**
204+
205+
🔗 **สมัครขอ API Key:** [Longdo Console](https://map.longdo.com/console/) (ฟรี!)
206+
207+
## 🔒 ความเป็นส่วนตัว
208+
209+
### การประมวลผลข้อมูล
210+
- การตรวจสอบข้อความทั้งหมดดำเนินการบนเซิร์ฟเวอร์ของ [Longdo](https://longdo.com/)
211+
- ในการตรวจสอบคำผิดในชุดคำสั่งจะไม่เก็บเนื้อหาข้อความไว้
212+
- ข้อความจะถูกใช้เพื่อวัตถุประสงค์ในการตรวจสอบการสะกดเท่านั้น
213+
214+
### การเก็บรวบรวมข้อมูล
215+
- เก็บสถิติการใช้งานแบบไม่ระบุตัวตนเพื่อปรับปรุงบริการ
216+
- ข้อมูลนี้รวมถึง:
217+
- จำนวนคำขอ
218+
- ขนาดของเนื้อหาที่ตรวจสอบ
219+
220+
### ความปลอดภัยของข้อมูล
221+
- ข้อมูลทั้งหมดถูกส่งผ่าน HTTPS ซึ่งมีความปลอดภัย
222+
- API key ใช้เพื่อยืนยันคำขอเท่านั้น
223+
- ไม่มีนโยบายหรือเก็บหรือต้องใช้ข้อมูลส่วนบุคคลใด ๆ นอกเหนือจาก API key
104224

105-
- **No personal data is stored.**
106-
- All Thai text sent is used **only** for spell-checking purposes.

src/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ async function postProof(text: string, apiKey: string): Promise<ApiResponse> {
3333
updateEmoji("$(debug-disconnect)");
3434
throw new Error("NetworkError");
3535
}
36-
console.log("API Key: ", apiKey);
3736
const response = await fetch("https://api.longdo.com/spell-checker/proof", {
3837
method: "POST",
3938
headers: {

src/extension.ts

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import { ErrorsResult } from "./interface/types";
66
import { Diagnostics } from "./diagnostics";
77
import { Configuration } from "./configuration";
88
import { showStatusBar, updateEmoji } from "./statusbar";
9+
import { showErrorAPIKey, showWarningAPIKey } from "./notification";
910

1011
let errorsResult: ErrorsResult[] = [];
1112
let markCheckList: ErrorsResult[] = [];
13+
let checkCountWithDefaultKey = 0;
14+
const DEFAULT_API_KEY = "longdospellcheckervscodedemo";
15+
const NOTIFICATION_THRESHOLD = 3;
1216

1317
export function activate(context: vscode.ExtensionContext) {
1418
showStatusBar(context);
@@ -171,10 +175,6 @@ export function activate(context: vscode.ExtensionContext) {
171175
context.subscriptions.push(listenerDocumentSaved());
172176
}
173177

174-
let checkCountWithDefaultKey = 0;
175-
const DEFAULT_API_KEY = "longdospellcheckervscodedemo";
176-
const NOTIFICATION_THRESHOLD = 3;
177-
178178
async function onSpellCheck() {
179179
errorsResult = [];
180180
Diagnostics.clearDiagnostics();
@@ -192,19 +192,7 @@ async function onSpellCheck() {
192192
checkCountWithDefaultKey++;
193193

194194
if (checkCountWithDefaultKey >= NOTIFICATION_THRESHOLD) {
195-
const action = await vscode.window.showWarningMessage(
196-
"You're using the default API key. For best results, please set your own API key.",
197-
"Set API Key", "Get API Key", "Dismiss"
198-
);
199-
200-
if (action === "Set API Key") {
201-
vscode.commands.executeCommand(Command.OpenSetKey);
202-
return;
203-
} else if (action === "Get API Key") {
204-
vscode.commands.executeCommand(Command.openWebAPI);
205-
return;
206-
}
207-
195+
showWarningAPIKey();
208196
checkCountWithDefaultKey = 0;
209197
}
210198
}
@@ -213,7 +201,14 @@ async function onSpellCheck() {
213201
await textProcessor.processDocument({ document });
214202

215203
try {
216-
let results = await spellCheckPromises(apiKey);
204+
const textData = await textProcessor.getTextData();
205+
if (textData.length === 0) {
206+
return;
207+
}
208+
if (textData.length >= 3 && apiKey === DEFAULT_API_KEY) {
209+
showWarningAPIKey();
210+
}
211+
let results = await spellCheckPromises(apiKey, textData);
217212
results = results.filter(
218213
(error) => !markCheckList.some((mark) => mark.word === error.word)
219214
);
@@ -231,20 +226,9 @@ async function onSpellCheck() {
231226
? error.message
232227
: "An error occurred while checking spelling.";
233228
const isErrorNetwork = errorMessage.includes("NetworkError");
234-
235229
const errorApiKeyEmpty = errorMessage.includes("API key is not set");
236230
if (errorApiKeyEmpty) {
237-
const actionItems = ["Yes", "No", "Get API Key"];
238-
const notification = await vscode.window.showWarningMessage(
239-
"API key is not set. Do you want to set it now?",
240-
...actionItems
241-
);
242-
243-
if (notification === "Yes") {
244-
vscode.commands.executeCommand(Command.OpenSetKey);
245-
} else if (notification === "Get API Key") {
246-
vscode.commands.executeCommand(Command.openWebAPI);
247-
}
231+
showErrorAPIKey();
248232
return;
249233
}
250234

0 commit comments

Comments
 (0)