質問編集履歴
1
内容を変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
vscodeの拡張機能として、
|
2
|
-
値域を表現する語の係り受け先の語をハイライトするというプログラムを作成してい
|
2
|
+
値域を表現する語の係り受け先の語をハイライトするというプログラムを作成しています。
|
3
|
-
|
3
|
+
プログラムとしては、あらかじめ用意したjsonファイルを読み込みその情報を元に
|
4
|
-
|
4
|
+
特定の語をハイライトするようにしている。
|
5
|
-
これを値域を表現する語が記載されている文章内だけに反映させるようなことは
|
6
|
-
出来ないでしょうか?
|
7
5
|
|
6
|
+
<parent_dict.json>
|
7
|
+
強時間:[現在=>設置している,
|
8
|
+
(現在=>設置している
|
9
|
+
]
|
10
|
+
というように左辺に値域を表現する語、右辺に係り受け先の語を保存している
|
11
|
+
|
12
|
+
|
13
|
+
困っていることとして
|
14
|
+
例えば、
|
15
|
+
・ある場所に現在設置しているものを使用する。
|
16
|
+
・(現在設置しているものの仕様)
|
17
|
+
のような2つの文章があった時に、本当であれば
|
18
|
+
1行目の「現在」と「設置している」、2行目の「(現在」と「設置している」を
|
19
|
+
ハイライトで表示して欲しいのですが、なぜか、
|
20
|
+
1行目の「現在」と2行目の「設置している」がハイライトで表示されないというバグが発生しています。
|
21
|
+
|
22
|
+
indexOfで探しているからなのか、それとも取得した情報が何かしらで更新されてしまっているのか
|
23
|
+
原因が分からなくて困っています。
|
8
24
|
初心者なので、助言を頂けると幸いです。よろしくお願いします。
|
9
25
|
|
10
26
|
```TypeScript
|
@@ -32,53 +48,44 @@
|
|
32
48
|
const activeEditor = vscode.window.activeTextEditor;
|
33
49
|
const text = activeEditor.document.getText(); //ドキュメント取得
|
34
50
|
|
35
|
-
|
51
|
+
//強時間
|
36
|
-
let timeWord = timeWordList[0].split('=>');
|
37
|
-
let rangeWordreg = timeWord[0];
|
38
|
-
let relationWordreg = timeWord[1];
|
39
|
-
for(let i =
|
52
|
+
for (let i = 0; i < strengthTimeWordList.length; i++){
|
40
|
-
|
53
|
+
let word = strengthTimeWordList[i].split('=>');
|
41
|
-
rangeWordreg = rangeWordreg + "|" + word[0];
|
42
|
-
relationWordreg = relationWordreg + "|" + word[1];
|
43
|
-
}
|
44
|
-
|
54
|
+
if(text.indexOf(word[0]) !== -1 && text.indexOf(word[1],text.indexOf(word[0])) !== -1){
|
45
|
-
const relationWord = eval("/" + relationWordreg + "/g;");
|
46
55
|
|
47
|
-
|
56
|
+
//値域、状態値を表現する語を抽出
|
48
|
-
let time_result;
|
49
|
-
let time_relation_result;
|
50
|
-
while(time_result = rangeWord.exec(text)){
|
51
|
-
|
57
|
+
const startPos = activeEditor.document.positionAt(text.indexOf(word[0]));
|
52
|
-
|
58
|
+
const endPos = activeEditor.document.positionAt(text.indexOf(word[0]) + word[0].length);
|
53
|
-
|
59
|
+
const strengthtime_decoration = { range: new vscode.Range(startPos, endPos)};
|
54
|
-
|
60
|
+
strengthTimeWords.push(strengthtime_decoration);
|
61
|
+
|
62
|
+
// 値域、状態値に係る語を抽出
|
63
|
+
const relation_startPos = activeEditor.document.positionAt(text.indexOf(word[1]));
|
64
|
+
const relation_endPos = activeEditor.document.positionAt(text.indexOf(word[1]) + word[1].length);
|
65
|
+
const strengthtime_related_decoration = {range:new vscode.Range(relation_startPos,relation_endPos)};
|
66
|
+
dependencyRelationWords.push(strengthtime_related_decoration);
|
67
|
+
|
55
|
-
|
68
|
+
strengthtimeCount++;
|
69
|
+
}
|
56
70
|
}
|
57
|
-
//値域、状態値に係る語を抽出
|
58
|
-
while(time_relation_result = relationWord.exec(text)){
|
59
|
-
const relation_startPos = activeEditor.document.positionAt(time_relation_result.index);
|
60
|
-
const relation_endPos = activeEditor.document.positionAt(time_relation_result.index + time_relation_result[0].length);
|
61
|
-
const time_related_decoration = {range:new vscode.Range(relation_startPos,relation_endPos)};
|
62
|
-
dependencyRelationWords.push(time_related_decoration);
|
63
|
-
}
|
64
71
|
|
65
72
|
|
66
73
|
activeEditor.setDecorations(timeMarkerDecoration,timeWords);
|
67
74
|
activeEditor.setDecorations(dependencyRelation,dependencyRelationWords);
|
68
75
|
|
69
|
-
console.log("時間:" +
|
76
|
+
console.log("強時間:" + strengthtimeCount);
|
70
77
|
}
|
71
78
|
decorateWord();
|
72
79
|
}));
|
73
80
|
|
74
|
-
//時間に色付け
|
81
|
+
//強時間に色付け
|
75
|
-
const
|
82
|
+
const strengthTimeMarkerDecoration = vscode.window.createTextEditorDecorationType({
|
76
83
|
'borderWidth': '1px',
|
77
84
|
'borderRadius': '2px',
|
78
85
|
'borderStyle': 'solid',
|
79
|
-
// 'backgroundColor': 'rgba(
|
86
|
+
// 'backgroundColor': 'rgba(0, 0, 255, 0.3)',
|
80
87
|
'backgroundColor': 'rgba(128, 128, 0, 0.3)',
|
81
|
-
// 'color':'
|
88
|
+
// 'color':'blue'
|
82
89
|
'color':'orange'
|
83
90
|
});
|
84
91
|
|
@@ -92,13 +99,4 @@
|
|
92
99
|
});
|
93
100
|
}
|
94
101
|
|
95
|
-
```
|
102
|
+
```
|
96
|
-
<parent_dict.json>
|
97
|
-
日単位で=>こと。
|
98
|
-
※左辺が値域を表現する語、右辺がそれに係る語
|
99
|
-
|
100
|
-
<出力結果>
|
101
|
-
今日の献立を見ることができる**こと。**
|
102
|
-
**日単位**でスケジュールの編集ができる**こと。**
|
103
|
-
※太字がハイライトされる部分(現状)
|
104
|
-
理想は「日単位で~こと。」の部分だけハイライトすること
|